-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTranslation.m
78 lines (64 loc) · 1.52 KB
/
Translation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TRANSLATION I X- och Y-LED %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Translation x -led
close all
values = 101;
%time = linspace(0, values);
mass = 0.5; %kg
frictionStill = 0.5;
frictionMove = 0.2;
step = 0.01; %step size
velx = zeros(values,1);
posx = zeros(values,1);
accx = zeros(values,1);
force = zeros(values,1);
force(1) = 0.6; %newton
forceAngle = 1;%radian
for index = 1:values
if ( cos(forceAngle) * force(index) >= frictionStill)
accx(index) = 1/mass * (cos(forceAngle) * force(index) - frictionMove * velx(index));
velx(index+1) = velx(index) + step * accx(index);
posx(index+1) = posx(index) + step * velx(index);
else
accx(index) = 0;
velx(index+1) = 0;
posx(index+1) = 0;
end
end
plot(accx);
figure
plot(velx),
figure
plot(posx);
%% Translation y-led
close all
values = 101;
mass = 0.5; %kg
frictionStill = 0.5;
frictionMove = 0.2;
step = 0.01; %step size
vely = zeros(values,1);
posy = zeros(values,1);
posy(1) = 0.2; %start position on y-axis
accy = zeros(values,1);
force = zeros(values,1);
force(1) = 10; %newton
forceAngle = 1;%radian
gravity = 9.82; % m/s^2
for index = 1:values
if posy(index) > 0
accy(index) = 1/mass * (sin(forceAngle) * (force(index) - gravity));
vely(index+1) = vely(index) + step * accy(index);
posy(index+1) = posy(index) + step * vely(index);
else
accy(index) = 0;
vely(index+1) = 0;
posy(index+1) = 0;
end
end
plot(accy);
figure
plot(vely),
figure
plot(posy);