Which method to use to calculate average velocity and what are the assumptions of the each method? - distance

i learned to calculate average velocity between two intervals. For the below table i calculated average velocity by calulating velocitties at 10 and 15 by information given and average of both them will be the average velocity at 12.5sec. But most calculate average velocity by first method. Both answers will be completely different.
I want to understand the assumptions and when to use which method.
Time (s)
Distance (m)
Velocity (m/s)
0
0
0
5
55
11
10
120
12
15
200
13.33
20
270
13.5
FIRST METHOD
average velocity = (202m - 122m)/(15s - 10s)
average velocity = 80m/5s
average velocity = 16m/shere
SECOND METHOD
velocity = (122 m)/(10 s) = 12.2m/s
velocity = (202 m)/(15 s) = 13.4667 m/s
average velocity = (13.4667 m/s + 12.2 m/s)/2
average velocity = 12.8333 m/s

Related

Calculate acceleration from data points

I have a servo motor, and this servo motor I would like to make it follow a "motion pattern" as closely as possible, and use the same value for acceleration and deceleration.
The attach picture illustrates the "motion pattern" (Y = velocity, X = Time)
motion pattern:
accelerates 0m/s to 0.100m/s.
constant velocity 0.100m/s for 4 sec.
decelerates to negative ?m/s.
accelerates to 0m/s, and motor position = 0.
How can i calculate the acceleration and deceleration?
What i have tried so far is:
Time = (total time - constant velocity time) 10 - 4 = 6sec.
Distances = (total distances - constant velocity distances ) 1 - 0.4 = 0.6meter.
acceleration = (2 * distances / (time^2) 2 * 0.6 / sqr(6) = 0.0333m/s.
But with this acceleration it over shoots in the negative direction by 500mm.
Take a look at the PLC Open motion function blocks, for example the MC_MoveRelative and the MC_MoveContinuesRelative block:
(Beckhoff documentation)
As Sergey already stated you can use those blocks to create a motion profile by entering all the parameters you need and integrating the blocks in a step chain.

Unity predict endpoint from current velocity

My rocket's rigidbody velocity is Vector2(0,100) when I call a function. How can I calculate the world coordinate (enpoint) when the velocity reaches 0?
Gravity should be included in the formula.
Thanks!
It sounds like you want the integral of the velocity function, which should provide the total distance respective to time.
Your velocity is going to be v = (100 - ('t'ime * 'g'ravity)). We can solve for time like t = (-v + 100)/g -> t = (0 + 100)/g = 100/g. So you should reach zero velocity at t = 100/g (assuming all the same units).
The integral of your velocity will give you distance traveled. An integral calculator is here: http://www.integral-calculator.com/
The integral function of your velocity is 100t - (g*t^2)/2
From zero to a particular time t, you can just plug and play. So for example, if for a particular gravity you reach zero velocity at t = 10 seconds, you will have traveled (100 * 10) - ((g * 10^2)/2) distance. (so for gravity 9, you would get 1000 - (9 * 100)/2 = 550 units
Edit: To be clear - first you want to calculate how long it takes to get to velocity zero at a particular starting velocity and gravity:
t = vStart/g
Then plug that time value into the integral function above:
distance = (vStart * t) - ((g * t^2)/2)
(or clearly you could turn it into one function by replacing t with vStart/g in the second function, but if I were coding I would definitely calculate them in two steps to provide a sanity check in case my units were wrong)

Yaw error calculation for a wind turbine using matlab

We know theoretically that
yaw error = wind direction - nacelle direction
After I have wind direction and nacelle direction data sets and hence calculated yaw error using above formula. I have calculated the absolute value of yaw error. Once I calculated the yaw error values I found that this calculation is not correct and hence I have to modify further with this formula
Error = 360 - yaw error
So basically I have to run a for look which is going to check my each yaw error value and if there is some wrong with that data it must replace with original data.. for example if my yaw error values are 10,20,30,40,300. it seems there is a wrong with 300 value because of quadrant changes hence it would replace with
error = 360 - 300 = 60. I have written a code for this below :
for i = 1:yaw error
if yaw_error > 180
error = 360 -yaw_error
else
end
end
yaw error = [yaw error error];
Can you help me where I am wrong ??
Thanks in advance :)
The one-liner of Umar is correct and elegant.
For your understanding, I have debuged your original code to:
yaw_error = [ 10,20,30,40,300]
for i = 1:numel(yaw_error)
if yaw_error(i) > 180
yaw_error(i) = 360 -yaw_error(i);
end
end;
yaw_error
From what I understand from your question
lets say x is a matrix of yaw error values
x = [10 20 30 40 190 160 70 120 300 180 30]
you find the indices of the values greater than 180
z = find(x > 180)
z =
5 9
subtract them from 360
>> d =360 - x(z)
d =
170 60
and place them back in the orignal matrix
>> x(z) = d
x =
x =
10 20 30 40 170 160 70 120 60 180 30
One-liner would be
x(find(x > 180)) = 360 - x(find(x > 180)) or x(x>180)=360-x(x>180)

Plotting speed and distance calculated using accelerometer

I am working on basic distance calculation using accelerometer by dragging object on a single axis for physics class in MATLAB and have problem with plotting data.
My steps are:
1) After calibrating device to read zero g on every axis, I eliminate drift errors:
X_real = X_sample - X_calibrated;
if(X_real <= X_drift )
{
X_real = 0;
}
Where X_drift is 2 mg (From datasheet of accelerometer)
2) Calculate velocity:
velocity = 0; % On start
% Integration
v(i) = v(i-1) - x(i-1)-(x(i)+x(i-1)+x(i-2)+x(i-3))/4;
%Check if we stopped
if(x(i-1)==0 && x(i)==0)
v(i)=0;
end
%Check if velocity is under 0 (Not allowed)
if(v(i) < 0)
v(i)=0;
end
velocity = velocity + v(i);
3) Calculate distance:
distance = 0; % On start
%Integration
s(i) = s(i-1) + v(i-1) + (v(i)-v(i-1)-v(i-2)-v(i-3))/4;
distance = distance + s(i);
After testing this by dragging accelerometer on table 20 cm i got these results:
velocity = 0.09 m/s
distance = 0.21 m
time = 3.2s
Error of 1 cm is OK for classroom.
Chart tells something different:
I tried to plot distance after this:
s(i) = s(i)+s(i-1);
And got 21 cm on chart but after 6 s not after 4 s where it should be.
What am I doing wrong?
*UPDATE: Position y value is in mm not cm! Sorry
Im sorry for asking for help, i thought my formulas were ok, but they didn't. After step by step calculations my final solution is:
1) Velocity:
v(i) = v(i-1) - x(i-1)-(x(i)+x(i-1))/2;
2) Distance:
s(i) = s(i-1) + v(i-1)+(v(i)+v(i-1))/2;
And chart is:
Sorry once more time. I hope this will help someone calculating velocity and distance. It surely helped me as lesson to better study my code next time before asking for help.

Calibrating an accelerometer

I have a device which contains an accelerometer. I'm looking for calibrating my 3D accelerometer.
I'm proceeding as follows:
The first time, I put my device in a flat position (rest) and I obtained these values :
x = -0.02
y = -0.02
z = -1.02
I applied Pythagoras's theorem to calculate total acceleration : A = sqrt(x*x + y*y + z*z)
Normally, when I subtract -1 (9.8 m/s2) from A, it should give 0 m/s but in my case it gives me : 0.01, so can I consider that my accelerometer is calibrated with a litle error = 0.01 or should I subtract 0.01 from all my outputs data for each axes.
Thanks in advance
#Nadosh:
Yes, data acceleration is 3 bytes. x,y,z in order did you mean line this