-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDel1.m~
68 lines (55 loc) · 1.93 KB
/
Del1.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
%% Börja om efter ANNAS hjälp
values = 8001; %Antal samples
force = zeros(1, values);
force(1) = 100; %Newton
force(2) = 100; %Newton
radie = 0.03; %Meter
massa = 5; %kilogram
langd = 1; %Meter
bredd = 1; %Meter
g = 9.82; %m/s^2
Ff = 0.1; %Newton
CoR = 0.05;% bara ett tal mellan 0-1
acce = zeros(1, values);
hastighet = zeros(1, values);
vinkel = zeros(1, values);
vinkel(1) = pi/2; % Startvinkel, radian
% Om radie < Hmin -> tippar bakåt, Om radie > Hmax -> tippar framåt
Hmin = (((force(1)*langd)/2) - ((massa*g*bredd)/2) - ((Ff* langd)/2)) / force(1); %Meter
Hmax = (((force(1)*langd)/2) + ((massa*g*bredd)/2) - ((Ff* langd)/2)) / force(1); %Meter
troghet = massa/3*(langd^2+bredd^2); %kg/m^2
step = 1/1000; %Step size
ifsats = 0;
for idx = 2:values
if radie < Hmin % Faller bakåt
acce(1,idx) = ((1/troghet)*(force(idx)*radie) + g*massa*cos(vinkel(idx-1)));
hastighet(1,idx) = hastighet(idx-1) + step*acce(idx);
vinkel(1,idx) = (vinkel(idx-1) + (step*hastighet(idx)));
if vinkel(1,idx) > pi
vinkel(1,idx) = pi;
hastighet(1,idx) = -hastighet(idx-1)*CoR;
ifsats = 1;
end
loop = 1;
elseif radie > Hmax % Faller framåt
acce(1,idx) = (1/troghet)*(force(idx)*radie) + g*massa*cos(vinkel(idx-1));
hastighet(1,idx) = hastighet(idx-1) + step*acce(idx);
vinkel(1,idx) = (vinkel(idx-1) - (step*hastighet(idx)));
if vinkel(1,idx) < 0
vinkel(1,idx) = 0;
hastighet(1,idx) = -hastighet(idx-1)*CoR;
end
loop = 2;
else % Translateras endast
vinkel(1,idx) = 0;
hastighet(1,idx) = 0;
acce(1, idx) = 0;
loop = 3;
end
end
subplot(1,3,1)
plot(tid,acce);
subplot(1,3,2)
plot(tid, hastighet);
subplot(1,3,3)
plot(tid, vinkel);