main_MBsysPy.py 3.38 KB
Newer Older
Louis Beauloye's avatar
Louis Beauloye committed
1
2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
3
4
5
6
7
8
9
10
11
12
"""Example of multibody system computed with MBsysPy using Python project files.

Summary
-------
This template loads the data file *.mbs and execute:
   - the coordinate partitioning module
   - the direct dynamic module (time integration of equations of motion).
   - the equilibrium module
   - the modal module
   - the inverse dynamic module
Louis Beauloye's avatar
Louis Beauloye committed
13
"""
14
15
# Author: Robotran Team
# (c) Universite catholique de Louvain, 2021
Louis Beauloye's avatar
Louis Beauloye committed
16

17
# %%===========================================================================
Louis Beauloye's avatar
Louis Beauloye committed
18
# Packages loading
19
# =============================================================================
Louis Beauloye's avatar
Louis Beauloye committed
20
import sys
21
22
# Add path to the MBsysC build folder
sys.path.insert(1, "../../../MBsysC/build/python")
Louis Beauloye's avatar
Louis Beauloye committed
23
24
25
26

import MBsysPy as Robotran


27
# %%===========================================================================
Louis Beauloye's avatar
Louis Beauloye committed
28
# Project loading
29
30
31
32
33
# =============================================================================
mbs_data = Robotran.MbsData("../dataR/PendulumSpringC.mbs",
                            user_path="userfctR/userfctR_python",
                            symbolic_path="symbolicR/symbolicR_python"
                            )
Louis Beauloye's avatar
Louis Beauloye committed
34
35
print(mbs_data)

36
# %%===========================================================================
Louis Beauloye's avatar
Louis Beauloye committed
37
# Partitionning
38
# =============================================================================
Louis Beauloye's avatar
Louis Beauloye committed
39
40
mbs_data.process = 1
mbs_part = Robotran.MbsPart(mbs_data)
41
mbs_part.set_options(rowperm=1, verbose=1)
Louis Beauloye's avatar
Louis Beauloye committed
42
43
mbs_part.run()

44
# %%===========================================================================
Louis Beauloye's avatar
Louis Beauloye committed
45
# Equilibrium
46
# =============================================================================
Louis Beauloye's avatar
Louis Beauloye committed
47
48
mbs_data.process = 2
mbs_equil = Robotran.MbsEquil(mbs_data)
49
mbs_equil.set_options(method=1, senstol=1e-2, verbose=1)
Louis Beauloye's avatar
Louis Beauloye committed
50
51
mbs_equil.run()

52
# %%===========================================================================
Louis Beauloye's avatar
Louis Beauloye committed
53
# Modal Analysis
54
# =============================================================================
Louis Beauloye's avatar
Louis Beauloye committed
55
56
mbs_data.process = 4
mbs_modal = Robotran.MbsModal(mbs_data)
57
mbs_modal.set_options(save_result=1, save_anim=1, mode_ampl=0.2)
Louis Beauloye's avatar
Louis Beauloye committed
58
59
mbs_modal.run()

60
61
62
63
64
65
66
67
68
69
70
71
# %%===========================================================================
# Direct Dynamics, oneshot
# =============================================================================
mbs_data.process = 3
mbs_data.qd[1] = 1.5
mbs_dirdyn = Robotran.MbsDirdyn(mbs_data)
mbs_dirdyn.set_options(flag_oneshot=1)
mbs_dirdyn.run()

# %%===========================================================================
# Direct Dynamics, time integration
# =============================================================================
Louis Beauloye's avatar
Louis Beauloye committed
72
73
74
mbs_data.process = 3
mbs_data.qd[1] = 1.5
mbs_dirdyn = Robotran.MbsDirdyn(mbs_data)
75
76
mbs_dirdyn.set_options(dt0=1e-3, tf=0.1, save2file=1)
mbs_dirdyn.set_options(integrator="RK4", resfilename="RK4")
Louis Beauloye's avatar
Louis Beauloye committed
77
78
mbs_dirdyn.run()

79
# %%===========================================================================
Louis Beauloye's avatar
Louis Beauloye committed
80
# Inverse Dynamics
81
# =============================================================================
Louis Beauloye's avatar
Louis Beauloye committed
82
mbs_data.process = 6
83
mbs_data.reset()
Louis Beauloye's avatar
Louis Beauloye committed
84
85
mbs_data.set_qa(4)
mbs_data.set_qa(1)
86
mbs_data.set_qa(3)
Louis Beauloye's avatar
Louis Beauloye committed
87
88
mbs_data.set_qa(2)
mbs_invdyn = Robotran.MbsInvdyn(mbs_data)
89
90
91
92
mbs_invdyn.set_options(trajectoryqname="../resultsR/RK4_q.res")
mbs_invdyn.set_options(trajectoryqdname="../resultsR/RK4_qd.res")
mbs_invdyn.set_options(trajectoryqddname="../resultsR/RK4_qdd.res")
mbs_invdyn.set_options(t0=1.0, tf=2.0, dt=2.5e-3)
Louis Beauloye's avatar
Louis Beauloye committed
93
mbs_invdyn.run()