How to get total acceleration value from accelerometer(mpu 9150) - physics

I have the value of acceleration in all 3-axis ax,ay,az in unit g. I need the magnitude of total acceleration, so that I used the formula,
max_acc= sqrt(ax^2+ ay^2 + az^2)
My question is, is my approach correct or not?
If it is not correct, your any kind of suggestion will be a great help.
Thanks in advance!

Your approach is correct.
If you just want to have translational acceleration without gravity, you have to subtract the gravity first.
If your accelerometer for example is positioned in a way, that gravity is aligned with ay
you have to calculate:
acc = sqrt(ax^2 + (ay-g)^2 + az^2)

Related

how to do physics for space war?

I am trying to do a basic version of space war(http://en.wikipedia.org/wiki/Spacewar_%28video_game%29) but I cannot figure out how to do the inertia part
that is my code :
I should let the ship accelerate or slow down based on where it faces
model is the ship
vx and vy are velocity of x and y direction
theta are rotate degree
20 is for make it move slow
vx=model.vx+(cos (degrees model.theta))/20,
vy=model.vy+(sin (degrees model.theta))/20
but it does not seem right
Can someone help me?
I am horrible in physics!
A very accurate and efficient integration is to compute: PosNext = 2 * PosCurrent - PosPrevious + Acceleration*Timestep^2
It is called Verlet integration scheme. For Velocities you just update by: VelocityNext = (PosNext-PosCurrent)/TimeStep.
You can use your sine and cosine with the acceleration constant. Euler forward is not very accurate, try to avoid it.

When to start braking when heading for a position?

With only 1 dimension, you want to get to position X and stop there. you have a maximum acceleration A you can apply yourself; each frame you choose what direction to accelerate.
So if you have a velocity V, and want to stop at position X as fast as possible, how much of your maximum acceleration A do you apply yourself?
(If you are far away, you apply your maximum acceleration, but when you are close, you start braking. So based on your velocity and remaing distance, you need to decide when you begin to brake.)
The governing equation is x = v t + 0.5 a t^2
where x is distance, v is velocity, t is time, and a is acceleration in compatible units.
With no other constraints, in order to minimize your travel time, you will always apply maximum acceleration: Accelerate in the direction of the goal until you are halfway there, then accelerate in the direction of the origin until you stop.
If you have a maximum velocity, accelerate until you reach that maximum velocity, which will happen at some distance X away from the origin. When you are distance X away from the goal, accelerate back toward the origin.
Just dropping in with the answer to a more advanced version of this question I solved lately. You have v_0 at x_0, and want to reach position X, and have velocity V when reaching there. Acceleration is applied each small time step, e.g. 60 times per second.
So using the equation of motion x = v t + 0.5 a t^2, solve it for t with positive/negative acceleration applied, to see how fast one can reach x, regardless of end speed.
Also calculate how long it would take to reach V by applying the positive or negative acceleration. Whichever t is the highest, is the positive or negative acceleration to apply.
This causes objects to smoothly follow pahts such as sin(x), and if they are thrown off, they will elegantly slide back into it.

Physics - Projectile get launch angle to hit desired location?

I am programming a simple ball projectile in a game.
the update pretty much looks like:
velocity += gravity;
velocity *=0.9;
pos += vel;
Is there a way to set the angle and power of the launch in order to hit a point that is specified with the mouse?
like peggle, http://youtu.be/4KbNiWsgJck?t=45s
I know there is a solution that I have used several years ago, but I can't find it.
I believed it turned my update into a quadratic formula, or derived it or something.
It had two solutions that was solved with the quadratic equation.
ps- hopefully this could be in 3D, but I could use a 2D solution too because my curve would be 2D
any help?
thanks,
Dan
Yes, you can do this. If you can change the angle and speed, you have more variability than you need, so you have to find a reasonable set of parameters that will work, which isn't hard. The basic equations are:
x = x0 + t*v0x
y = y0 + v0yt + (1/2)ayt2
Here, x and y will be the points you want to hit, and t will be the time that you hit them. t won't show up in the final solution, but you'll use it as in intermediary to calculate the values you want.
Basically, then, pick a reasonable value for v0x. Using the x-equation, find what t will be when the target is hit. Then plug this value into the y-equation, and solve for v0y. This then will give you a pair of values of v0x and v0y that will work to hit the target.

Animation independent of frame rate

To make animation independent of frame rate, is it necessary to multiply the delta value by both velocity and acceleration?
// Multiply both acceleration and velocity by delta?
vVelocity.x += vAcceleration.x * delta;
vVelocity.y += vAcceleration.y * delta;
position.x += vVelocity.x * delta;
position.y += vVelocity.y * delta;
Should I apply delta to the velocity only and not acceleration?
Assuming your "delta" is the amount of time passed since last update:
Short answer: yes.
Long answer:
One way to check this sort of thing is to see if the units work out. It's not guaranteed, but usually if your units work out, then you've figured things correctly.
Velocity measures distance per unit time, and delta is time. So velocity times delta is (picking arbitrary units meters and seconds) (m/s) * s = m. So you can see that velocity times delta does create a distance, so that appears reasonable for position.
Acceleration measures velocity per unit time, that is, with the same units (m/s)/s. So, acceleration times delta is ((m/s)/s) * s = m/s. Looks like a velocity to me. We're good!
Yes, it is necessary to involve delta with both the velocity and the acceleration. They're both properties that are defined with respect to time (m/s for one, m/s/s for the other - units may vary), so delta should be used whenever they have to change non-instantaneously.

How to calculate deceleration needed to reach a certain speed over a certain distance?

I've tried the typical physics equations for this but none of them really work because the equations deal with constant acceleration and mine will need to change to work correctly. Basically I have a car that can be going at a large range of speeds and needs to slow down and stop over a given distance and time as it reaches the end of its path.
So, I have:
V0, or the current speed
Vf, or the speed I want to reach (typically 0)
t, or the amount of time I want to take to reach the end of my path
d, or the distance I want to go as I change from V0 to Vf
I want to calculate
a, or the acceleration needed to go from V0 to Vf
The reason this becomes a programming-specific question is because a needs to be recalculated every single timestep as the car keeps stopping. So, V0 constantly is changed to be V0 from last timestep plus the a that was calculated last timestep. So essentially it will start stopping slowly then will eventually stop more abruptly, sort of like a car in real life.
EDITS:
All right, thanks for the great responses. A lot of what I needed was just some help thinking about this. Let me be more specific now that I've got some more ideas from you all:
I have a car c that is 64 pixels from its destination, so d=64. It is driving at 2 pixels per timestep, where a timestep is 1/60 of a second. I want to find the acceleration a that will bring it to a speed of 0.2 pixels per timestep by the time it has traveled d.
d = 64 //distance
V0 = 2 //initial velocity (in ppt)
Vf = 0.2 //final velocity (in ppt)
Also because this happens in a game loop, a variable delta is passed through to each action, which is the multiple of 1/60s that the last timestep took. In other words, if it took 1/60s, then delta is 1.0, if it took 1/30s, then delta is 0.5. Before acceleration is actually applied, it is multiplied by this delta value. Similarly, before the car moves again its velocity is multiplied by the delta value. This is pretty standard stuff, but it might be what is causing problems with my calculations.
Linear acceleration a for a distance d going from a starting speed Vi to a final speed Vf:
a = (Vf*Vf - Vi*Vi)/(2 * d)
EDIT:
After your edit, let me try and gauge what you need...
If you take this formula and insert your numbers, you get a constant acceleration of -0,0309375. Now, let's keep calling this result 'a'.
What you need between timestamps (frames?) is not actually the acceleration, but new location of the vehicle, right? So you use the following formula:
Sd = Vi * t + 0.5 * t * t * a
where Sd is the current distance from the start position at current frame/moment/sum_of_deltas, Vi is the starting speed, and t is the time since the start.
With this, your decceleration is constant, but even if it is linear, your speed will accomodate to your constraints.
If you want a non-linear decceleration, you could find some non-linear interpolation method, and interpolate not acceleration, but simply position between two points.
location = non_linear_function(time);
The four constraints you give are one too many for a linear system (one with constant acceleration), where any three of the variables would suffice to compute the acceleration and thereby determine the fourth variables. However, the system is way under-specified for a completely general nonlinear system -- there may be uncountably infinite ways to change acceleration over time while satisfying all the constraints as given. Can you perhaps specify better along what kind of curve acceleration should change over time?
Using 0 index to mean "at the start", 1 to mean "at the end", and D for Delta to mean "variation", given a linearly changing acceleration
a(t) = a0 + t * (a1-a0)/Dt
where a0 and a1 are the two parameters we want to compute to satisfy all the various constraints, I compute (if there's been no misstep, as I did it all by hand):
DV = Dt * (a0+a1)/2
Ds = Dt * (V0 + ((a1-a0)/6 + a0/2) * Dt)
Given DV, Dt and Ds are all given, this leaves 2 linear equations in the unknowns a0 and a1 so you can solve for these (but I'm leaving things in this form to make it easier to double check on my derivations!!!).
If you're applying the proper formulas at every step to compute changes in space and velocity, it should make no difference whether you compute a0 and a1 once and for all or recompute them at every step based on the remaining Dt, Ds and DV.
If you're trying to simulate a time-dependent acceleration in your equations, it just means that you should assume that. You have to integrate F = ma along with the acceleration equations, that's all. If acceleration isn't constant, you just have to solve a system of equations instead of just one.
So now it's really three vector equations that you have to integrate simultaneously: one for each component of displacement, velocity, and acceleration, or nine equations in total. The force as a function of time will be an input for your problem.
If you're assuming 1D motion you're down to three simultaneous equations. The ones for velocity and displacement are both pretty easy.
In real life, a car's stopping ability depends on the pressure on the brake pedal, any engine braking that's going on, surface conditions, and such: also, there's that "grab" at the end when the car really stops. Modeling that is complicated, and you're unlikely to find good answers on a programming website. Find some automotive engineers.
Aside from that, I don't know what you're asking for. Are you trying to determine a braking schedule? As in there's a certain amount of deceleration while coasting, and then applying the brake? In real driving, the time is not usually considered in these maneuvers, but rather the distance.
As far as I can tell, your problem is that you aren't asking for anything specific, which suggests that you really haven't figured out what you actually want. If you'd provide a sample use for this, we could probably help you. As it is, you've provided the bare bones of a problem that is either overdetermined or way underconstrained, and there's really nothing we can do with that.
if you need to go from 10m/s to 0m/s in 1m with linear acceleration you need 2 equations.
first find the time (t) it takes to stop.
v0 = initial velocity
vf = final velocity
x0 = initial displacement
xf = final displacement
a = constant linear acceleration
(xf-x0)=.5*(v0-vf)*t
t=2*(xf-x0)/(v0-vf)
t=2*(1m-0m)/(10m/s-0m/s)
t=.2seconds
next to calculate the linear acceleration between x0 & xf
(xf-x0)=(v0-vf)*t+.5*a*t^2
(1m-0m)=(10m/s-0m/s)*(.2s)+.5*a*((.2s)^2)
1m=(10m/s)*(.2s)+.5*a*(.04s^2)
1m=2m+a*(.02s^2)
-1m=a*(.02s^2)
a=-1m/(.02s^2)
a=-50m/s^2
in terms of gravity (g's)
a=(-50m/s^2)/(9.8m/s^2)
a=5.1g over the .2 seconds from 0m to 10m
Problem is either overconstrained or underconstrained (a is not constant? is there a maximum a?) or ambiguous.
Simplest formula would be a=(Vf-V0)/t
Edit: if time is not constrained, and distance s is constrained, and acceleration is constant, then the relevant formulae are s = (Vf+V0)/2 * t, t=(Vf-V0)/a which simplifies to a = (Vf2 - V02) / (2s).