-
Notifications
You must be signed in to change notification settings - Fork 1
/
MBpointForce.m
62 lines (54 loc) · 1.9 KB
/
MBpointForce.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
classdef MBpointForce < MBforce
properties
sI % point on body where force is applied
lrf = true; % true if expressed in LRF, false if in GRF
funX; % time function for F_x(t)
funY; % time function for F_y(t)
end
methods
function obj = MBpointForce(varargin)
data = varargin{1};
obj = obj@MBforce(data.id, data.body1, []);
obj.sI = reshape(data.sP1, 2, 1);
syms t;
funXstr = data.funX;
funYstr = data.funY;
obj.funX = matlabFunction(eval(funXstr), 'vars', t);
obj.funY = matlabFunction(eval(funYstr), 'vars', t);
if strcmp(data.frame, 'GRF')
obj.lrf = false;
else
obj.lrf = true;
end
end
function print(obj)
print@MBforce(obj);
fprintf(' sI: (%g %g)\n', obj.sI(1), obj.sI(2));
if obj.lrf
frame = 'LRF (local)';
else
frame = 'GRF (global)';
end
fprintf(' reference frame: %s\n', frame);
fprintf(' force functions: %s\n', func2str(obj.funX));
fprintf(' %s\n', func2str(obj.funY));
end
function Q = eval(obj, t, qi, qdi)
% Evaluate X and Y components of the linear force.
F = [obj.funX(t); obj.funY(t)];
% Evaluate B matrix of the body.
[A,B] = MBbody.rotMat(qi(3));
% If the force is expressed in LRF, re-express it in GRF.
if obj.lrf
F = A * F;
end
% Assemble generalized force.
Q = [F; (B*obj.sI)'*F];
end
end
methods(Static)
function type = getType()
type = 'PointForce';
end
end
end