-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdemo_dynamic_simulation.m
59 lines (48 loc) · 2.02 KB
/
demo_dynamic_simulation.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
% Example of dynamic simulation
% -----------------------------------------------------------------------------
% This file is part of MBDE-MATLAB. See: https://github.com/MBDS/mbde-matlab
%
% MBDE-MATLAB is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% MBDE-MATLAB is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with MBDE-MATLAB. If not, see <http://www.gnu.org/licenses/>.
% -----------------------------------------------------------------------------
%%
addpath('toolbox_mbe');
%% Instance of multibody model:
mbs = mbeMechModelFourBars1();
%mbs = mbeMechModelFourBars2();
%mbs = mbeMechModelFiveBars1();
%mbs = mbeMechModelRodArray1dof();
%mbs = mbeMechModelPendulum1();
%% Instance of dynamical simulator:
% sim = mbeDynFormulationMatrixR();
sim = mbeDynFormulationI3AL();
% sim = mbeDynFormulationPenalty();
% sim = mbeDynFormulationLagrangeBaumgarte();
%% Select integrator:
% See options in mbeIntegratorTypes: intEuler, intTrapezoidal,...
% sim.integrator_type = mbeIntegratorTypes.intTrapezoidal;
sim.integrator_type = mbeIntegratorTypes.intI3AL;
% (Read the docs of mbeDynFormulationBase on this variable!)
%sim.integrate_indep_coords = 1; % Default
%sim.integrate_indep_coords = 0;
%% Run batch dyn simulation:
t_ini = 0.0;
t_end = 5;
dt = 5e-3;
[states,perf_stats]=sim.batch_dyn_solve(mbs,t_ini,t_end,dt);
%% Plot results:
figure,
ts=states.t(:); % time vector
plot(ts,states.q(:, mbs.indep_idxs(1) )),title('z(t) (1st DOF)');
% Show performance stats:
sim.plot_perf_stats(perf_stats);