- #1
Darkbound
- 22
- 0
Homework Statement
I am solving a kinematic problem, where I have a link that is attached to a rotational joint. I need to find the position of the joint for t=0..8, and I need to do it for every 0.01s. The problem comes from the fact that I have three stages for the velocity, during t = 0..0.1 it is accelerating, during t = 0.1..7.7 it maintains a constant velocity, and in t = 7.7..8 it is decelerating until it reaches 0.
I know:
initial θ = 20° = 0.3491 rad
The constant velocity for the second interval which is 0.1666667 rad/s
Homework Equations
1) a = v/t
2) x = x0 + vt + 1/2 * a * t^2
3) v = v0 + a*t
I will use x instead of theta in the equations bellow
The Attempt at a Solution
I used 1) to find the acceleration at the end point of the first time interval and the acceleration at the end point of the 3rd interval.
The way I approached it is, I know that in 0.1 seconds I need to reach the given velocity, so I just divided the velocity by the time
a_t1 = v/t = 1.6666667 rad/s^2
And the same for the deceleration, a_t3 = v/t = 0.55556 rad/s^2
Then I used these three equations to find the final angle:
x1(t) = x0 + v * t1 + 1/2 * a * t1^2 = 0.3491 + 0 * 0.1 + 1/2 * 1.666667 * 0.1^2 = 0.3574 rad
x2(t) = x1 + v * (t2 - t1) + 1/2 * a * (t2 - t1)^2 = 0.3574 + 0.166667 * (7.7 - 0.1) + 1 / 2 *0 * (7.7 - 0.1)^2 = 1.6241 rad
x3(t) = x2 + v * (t3 - t2) + 1/2 * a * (t3 - t2)^2 = 1.6241 + 0.166667 * (8 - 7.7) - 1/2 * 0.55556 * (8 - 7.7)^2 = 1.6491 rad
Or in degrees 94.485 degrees (I am calculating it with matlab, so allow for a tiny rounding error)
My first question is if that number is correct.
My second issue is, as I mentioned in the beginning, I need to be able to do it for a given time delta for the full motion, like every 0.01 second, and I should still arrive at the same number in the end, its after all the same motion just broken down into many tiny motions.
The way I tried to approach this is to again use three equations for the three time periods, but I also recalculated the velocity for every moment, since after the initial t=0 I have initial and final velocities, so the equations I used are:
v1(tnew) = v1(tnew - told) + a * (tnew - told)
x1(tnew) = x1(told) + v1old*(tnew - told) + 1/2 * acc * (tnew - told)^2
x2(tnew) = x2(told) + v2*(tnew - told)
v3(tnew) = v3(tnew - told) - 1/2 * acc * (tnew - told)^2
x3(tnew) = x3(told) + v3old*(tnew - told) - 1/2 * acc * (tnew - told)^2
The angle that I get after these calculations is 1.6474 radians or 94.387 degrees, which is very close to my other calculation. I am doing these calculations with MATLAB, so I don't know if there's simply some rounding error that adds up and causes the answer to be off by a little, theta is being recalculated 800 times, or if there is some issue with my formulas.
If I compare the results for both of my calculations I get:
x1 with t = 0.1 and my x1(tnew) when it reaches t=0.1, they both are the same
x2 with t = 7.7 and x2(tnew) when it reaches t = 7.7, I get 1.62406585... vs 1.62403807... or 93.052111 vs 93.0505273... degrees
x3 with t = 8 and x3(tnew) when it reaches t = 8, 1.6473714... vs 1.6490658... or 94.48451... vs 94.387482...
And most of the calculations happen with x2, so i am suspecting that mostly the error is in my final equation for x3
This is my MATLAB code
w2real = 0.1/6;
theta0 = deg2rad(20); % Initial angle of joint 2
t = [0 0.01:0.01:8]; % Time vector for the full motion
a2acc = w2real / 0.1; % Acceleration of joint 2
a2dec = w2real / 0.3; % Deceleration of joint 2
theta = zeros(size(t));
w2theta = zeros(size(t));
% Populating the first elements of d and theta with the initial conditions
theta(1) = theta0;
% Calculating theta at 3 points - t = 0:0.1, t = 0.1:7.7, t = 7.7:8
ntheta1 = theta0 + a2acc * tacc^2 / 2;
ntheta2 = ntheta1 + w2real * tnorm;
ntheta3 = ntheta2 + w2real * tdec - 1/2 * a2dec * (tdec)^2;
for n = 2:size(t, 2)
m = n - 1;
if (t(n) >= 0 && t(n) <= 0.1)
% acceleration
w2theta(n) = w2theta(n - 1) + a2acc * (t(n) - t(m));
theta(n) = theta(m) + (w2theta(m))*(t(n) - t(m)) + (1 / 2) * a2acc * (t(n) - t(m))^2;
elseif (t(n) > 0.1 && t(n) <= 7.7)
% no acceleration
w2theta(n) = w2real;
theta(n) = theta(m) + w2real * (t(n) - t(m));
elseif (t(n) > 7.7 && t(n) <= t(end))
% deceleration
w2theta(n) = w2theta(m) - a2dec * (t(n) - t(m));
theta(n) = theta(m) + (w2theta(m))*(t(n) - t(m)) - (1 / 2) * a2dec * (t(n) - t(m))^2;
end
end
disp('Ntheta1 vs Discrete theta1')
[ntheta1 theta(11)]
disp('Ntheta2 vs Discrete theta2')
[ntheta2 theta(771)]
disp('Ntheta3 vs Discrete theta3')
[ntheta3 theta(end)]
Is my approach and signs correct and is this simply a rounding error that builds up, or is there something that I am doing wrong?
EDIT: I have tried with different times, 1s acceleration, 5s maintaining, 2s deceleration and the error for the final value was much, much smaller, so I am guessing that the differences that I get are simply due to the rounding that MATLAB does on each of the iterations.
1.432399183732219
vs
1.432399183732199
Last edited: