-
Notifications
You must be signed in to change notification settings - Fork 0
/
runExample.m
53 lines (40 loc) · 1.63 KB
/
runExample.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
%% Setup variables.
setupRopeWorkspace
%% This will give us 100 seconds of simulation.
numIterations = 5000;
deltaT = 0.02;
timeSteps = 10;
%% Configure the physics.
% Configure the rigid rope physics. This will create the L variable
% (the Lagrangian).
disp('Configuring rope physics..');
ropeRigid
% S==0 is the Euler-Lagrange equation for the system. S==-force makes the
% system be affected by a force (roughly). thetaDD is just the symbol for
% the second time derivative of theta.
disp('Computing Euler-Lagrange..');
[S, thetaDD] = getEulerLagrange( L, theta, thetaD, t );
%% Solve the linear system (assuming it is linear!).
disp('Getting A and b from the linear system.');
[A,b] = equationsToMatrix(S==0.2*thetaD, thetaDD);
%% Simplify A and b.
% This takes a long time (~6 mins if numRopeSegments == 30), but without it
% simulate would take a LOT longer and it would be impossible to
% re-simulate with different starting parameters.
disp('Simplifying A and b. This can take a couple of minutes!');
A = simplify(A);
b = simplify(b);
%% Create a matlab function for thetaDD.
% thetaDDCompute is a function that takes (theta, thetaD) as arguments and
% spits out thetaDD. Use getThetaDDFunctionLinear if the system is in the
% form A*thetaDD = b.
disp('Solving for thetaDD..');
thetaDDCompute = getThetaDDFunctionLinear(theta, thetaD, A, b );
%% Simulate the system.
disp('Simulating..');
thetaSnapshots = simulate( initTheta, initThetaD, thetaDDCompute, ...
numIterations, deltaT / timeSteps, timeSteps );
disp('To playback, type')
disp(' playbackSnapshots')
disp('To avoid recomputing rope positions, type')
disp(' playbackSnapshotsRender')