Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
robotran
mbsysc
Commits
dcfac19f
Commit
dcfac19f
authored
Aug 08, 2019
by
Louis Beauloye
Browse files
[Ctypes] doc
parent
670a2c61
Changes
3
Hide whitespace changes
Inline
Side-by-side
MBsysC/mbs_interface/MBsysPy/mbsyspy/mbs_data.py
View file @
dcfac19f
...
...
@@ -243,6 +243,33 @@ class MbsData(object):
Zd : ndarray
Numpy array containing the current values of the speed (spreading)
between of the points of a link.
Example
-------
>>> mbs_data = robotran.MbsData("../dataR/UExampleProject.mbs")
>>> mbs_data.user_model["MyUserModel"]["MyScalar"] = 3.0
>>> print(mbs_data.user_model["MyUserModel"]["MyScalar"])
3.0
>>> #get a copy of the scalar
>>> a = mbs_data.user_model["MyUserModel"]["MyScalar"]
>>> a = 2
>>> print(mbs_data.user_model["MyUserModel"]["MyScalar"])
3.0
>>> print(mbs_data.user_model["MyUserModel"]["MyVector"])
array([1.0, 3.0])
>>> mbs_data.user_model["MyUserModel"]["MyVector"] = [1.0, 2.0]
>>> print(mbs_data.user_model["MyUserModel"]["MyVector"])
array([1.0, 2.0])
>>> b = mbs_data.user_model["MyUserModel"]["MyVector"]
>>> b[1] = 10.0
>>> print(mbs_data.user_model["MyUserModel"]["MyVector"])
array([1.0, 10.0])
>>> b = np.array([2.0, 4.0])
>>> print(mbs_data.user_model["MyUserModel"]["MyVector"])
array([1.0, 10.0])
"""
def
__init__
(
self
,
name
,
user_path
=
None
,
symbolic_path
=
None
):
...
...
@@ -390,7 +417,7 @@ class MbsData(object):
self
.
__generate_id__
()
#UserModel
self
.
user_model
=
_
Strict
Dict
()
self
.
user_model
=
_
UserModel
Dict
()
self
.
__load_user_model__
()
...
...
@@ -412,11 +439,14 @@ class MbsData(object):
def
__load_user_fct__
(
self
,
user_path
=
None
):
"""
Load all user function where arguments are in MbsData instance.
Load all user function
s
where arguments are in MbsData instance.
Only load the user functions in which the arguments are not
dependent of another module instance (ie. MbsPart, MbsDirdyn...).
The other user function will be loaded when a module is created.
The other user functions will be loaded when a module is created.
The functions will be assigned to the MbsData instance when
the 'run' function in other modules is called and unassigned
at the end.
The loader user functions are :
- user_derivatives (from derivatives.py)
...
...
@@ -499,12 +529,15 @@ class MbsData(object):
def
__load_symb_fct__
(
self
,
symb_path
=
None
):
"""
Load all symbolic function if all args are in MbsData instance.
Load all symbolic function
s
if all args are in MbsData instance.
Only load the symbolic functions in which the arguments are not
dependent of another module instance (ie. MbsPart, MbsDirdyn...).
The other symbolic function will be loaded when a module is
The other symbolic function
s
will be loaded when a module is
instancied.
The functions will be assigned to the MbsData instance when
the 'run' function in other modules is called and unassigned
at the end.
The loader symbolic functions are :
- mbs_accelred (from mbs_accelred_MBSNAME.py)
...
...
@@ -594,15 +627,14 @@ class MbsData(object):
def
__assign_user_fct__
(
self
):
"""
Assign all user function where arguments are in MbsData instance.
Only assign the user functions in which the arguments are not
dependent of another module instance (ie. MbsPart, MbsDirdyn...).
The other user function will be assigned when a module is created.
Assign all user functions if all args are in MbsData instance.
The functions will be assigned to the MbsData instance when
the 'run' function in other modules is called and unassigned
at the end.
Assign and wrap python user functions in which the arguments are
not dependent of another module instance (ie. MbsPart, MbsDirdyn...).
Store the functions in the MbsData instance and assign the pointer
of functions in the C structure.
The other user functions will be assigned when a module is
instancied.
"""
data_c_ptr
=
self
.
mbs_data_ptr
.
contents
...
...
@@ -635,22 +667,15 @@ class MbsData(object):
def
__assign_symb_fct__
(
self
):
"""
Assign all symbolic function if all args are in MbsData instance.
Assign all symbolic function
s
if all args are in MbsData instance.
Only assign the symbolic functions in which the arguments are not
dependent of another module instance (ie. MbsPart, MbsDirdyn...).
The other symbolic function will be assigned when a module is
Assign and wrap python symbolic functions in which the arguments are
not dependent of another module instance (ie. MbsPart, MbsDirdyn...).
Store the functions in the MbsData instance and assign the pointer
of functions in the C structure.
The other user functions will be assigned when a module is
instancied.
Assign and wrap python user functions in which the arguments are not
dependent of another module instance (ie. MbsPart, MbsDirdyn...).
Store the functions in the MbsData instance
and assign the pointer of functions in the C structure
The functions will be assigned to the MbsData instance when
the 'run' function in other modules is called and unassigned
at the end.
"""
data_c_ptr
=
self
.
mbs_data_ptr
.
contents
...
...
@@ -780,7 +805,7 @@ class MbsData(object):
for
i
in
range
(
infos_c_ptr
.
user_models
.
contents
.
n_user_model
):
user_model_list
=
infos_c_ptr
.
user_models
.
contents
.
user_model_list
[
i
].
contents
name
=
user_model_list
.
name
.
decode
(
'utf-8'
)
self
.
user_model
[
name
]
=
_
Strict
Dict
()
self
.
user_model
[
name
]
=
_
UserModel
Dict
()
self
.
user_model
[
name
].
_parent_key
=
name
self
.
user_model
[
name
].
_locked
=
False
self
.
user_model
[
name
].
_type
=
dict
()
...
...
@@ -1205,18 +1230,27 @@ class MbsData(object):
return
ctypes
.
string_at
(
self
.
mbs_data_ptr
.
contents
.
mbs_name
).
decode
(
"utf-8"
)
class
_StrictDict
(
dict
):
class
_UserModelDict
(
dict
):
"""
Class defined for user models, inherites from dict
setitem and getitem function were updated
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
dict
.
__init__
(
self
,
*
args
,
**
kwargs
)
self
.
_locked
=
True
"flag that locks the addition of a new item"
self
.
_parent_key
=
None
self
.
_type
=
None
"key of the parent dict, None if not"
self
.
_type
=
None
"type of the parameter, None if not"
def
__setitem__
(
self
,
key
,
value
):
if
self
.
_locked
==
True
:
# if it is a parameter
if
not
(
self
.
_type
is
None
):
if
self
.
_type
[
key
]
==
1
:
if
type
(
value
)
is
float
:
...
...
MBsysC/mbs_interface/MBsysPy/mbsyspy/mbs_dirdyn.py
View file @
dcfac19f
...
...
@@ -47,7 +47,7 @@ from ..mbsysc_loader.callback import mbs_dirdyna_wrap
#==============================================================================
# Global parameter of the current module
#==============================================================================
__DEBUG__
=
Fals
e
__DEBUG__
=
Tru
e
__MODULE_DIR__
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
...
...
@@ -130,7 +130,7 @@ class MbsDirdyn(object):
# Storing Results
self
.
results
=
MbsResult
(
self
.
mbs
)
self
.
get
_results
=
True
self
.
store
_results
=
True
# Exposing some memory
if
__DEBUG__
:
print
(
"DEBUG>> Exposing MbsDirdyn fields"
)
...
...
@@ -277,7 +277,9 @@ class MbsDirdyn(object):
def
__assign_user_fct__
(
self
):
"""
Assign user function where some args depend on MbsDirdyn module.
Assign and wrap python user function where some args depend
on MbsDirdyn module. Store the functions in the MbsData instance
and assign the pointer of functions in the C structure
"""
# cons_hJ
self
.
ptrs_to_user_fcts
[
"user_cons_hJ"
]
=
user_cons_hJ_wrap
(
lambda
h
,
Jac
,
mbs
,
tsim
:
self
.
user_cons_hJ
(
self
.
_huserc
,
self
.
_Juserc
,
self
.
mbs
,
tsim
))
...
...
@@ -303,7 +305,9 @@ class MbsDirdyn(object):
def
__assign_symbolic_fct__
(
self
):
"""
Assign symbolic function where some args depend on MbsDirdyn module.
Assign and wrap python symbolic function where some args depend
on MbsDirdyn module. Store the functions in the MbsData instance
and assign the pointer of functions in the C structure
"""
# mbs_cons_hJ
...
...
@@ -377,7 +381,24 @@ class MbsDirdyn(object):
if
__DEBUG__
:
print
(
"DEBUG>> MbsDirdyn pointer deleted"
)
def
run
(
self
):
"""
Run a direct dynamics analysis
Options can be setted with set_options
Options can be retrieved with get_options
Results are stored in the field results (if store_results == True)
Examples
--------
>>> mbs_data = robotran.MbsData("../dataR/ExampleProject.mbs")
>>> mbs_dirdyn = robotran.MbsDirdyn(mbs_data)
>>> mbs_dirdyn.set_options(t0 = 5, tf = 10)
>>> mbs_dirdyn.get_options("t0", "tf")
(5.0, 10.0)
>>> mbs_dirdyn.run()
"""
# Assing required user functions
self
.
__assign_user_fct__
()
self
.
mbs
.
__assign_user_fct__
()
...
...
@@ -387,7 +408,7 @@ class MbsDirdyn(object):
self
.
mbs
.
__assign_symb_fct__
()
if
not
self
.
get
_results
:
if
not
self
.
store
_results
:
libmodules
.
mbs_run_dirdyn
(
self
.
mbs_dirdyn_ptr
,
self
.
mbs
.
mbs_data_ptr
)
else
:
#save2file forced to 1 because if buffers don't have the complete results, results are loaded from files
...
...
@@ -560,7 +581,7 @@ class MbsDirdyn(object):
n_freeze : int
number of time step when the jacobian is freezed (computed once at the start of the n_freeze time steps)
default = 0
get
_results : boolean
store
_results : boolean
1 to save a copy of the results from the buffers
default = 1
...
...
@@ -658,8 +679,8 @@ class MbsDirdyn(object):
self
.
mbs_dirdyn_ptr
.
contents
.
options
.
contents
.
dt_max
=
value
elif
key
==
"n_freeze"
:
self
.
mbs_dirdyn_ptr
.
contents
.
options
.
contents
.
n_freeze
=
value
elif
key
==
"
get
_results"
:
self
.
get
_results
=
value
elif
key
==
"
store
_results"
:
self
.
store
_results
=
value
else
:
print
(
">>DIRDYN>> The option "
+
key
+
" is not defined in this module"
)
...
...
@@ -760,8 +781,8 @@ class MbsDirdyn(object):
options
.
append
(
self
.
mbs_dirdyn_ptr
.
contents
.
options
.
contents
.
dt_max
)
elif
key
==
"n_freeze"
:
options
.
append
(
self
.
mbs_dirdyn_ptr
.
contents
.
options
.
contents
.
n_freeze
)
elif
key
==
"
get
_results"
:
options
.
append
(
self
.
get
_results
)
elif
key
==
"
store
_results"
:
options
.
append
(
self
.
store
_results
)
else
:
print
(
">>DIRDYN>> The option "
+
key
+
" is not defined in this module"
)
...
...
MBsysC/mbs_interface/MBsysPy/mbsyspy/mbs_part.py
View file @
dcfac19f
...
...
@@ -173,7 +173,9 @@ class MbsPart(object):
def
__assign_user_fct__
(
self
):
"""
Assign user function where some args depend on MbsPart module.
Assign and wrap python user function where some args depend
on MbsPart module. Store the functions in the MbsData instance
and assign the pointer of functions in the C structure
"""
...
...
@@ -184,7 +186,9 @@ class MbsPart(object):
def
__assign_symbolic_fct__
(
self
):
"""
Assign symbolic function where some args depend on MbsPart module.
Assign and wrap python symbolic function where some args depend
on MbsPart module. Store the functions in the MbsData instance
and assign the pointer of functions in the C structure
"""
self
.
ptrs_to_symb_fcts
[
"mbs_cons_hJ"
]
=
mbs_cons_hJ_wrap
(
lambda
h
,
Jac
,
mbs
,
tsim
:
self
.
__callback_mbs_cons_hJ
(
self
.
mbs_cons_hJ
,
h
,
Jac
))
...
...
@@ -232,6 +236,23 @@ class MbsPart(object):
return
def
run
(
self
):
"""
Run a coordinate partitioning
Options can be setted with set_options
Options can be retrieved with get_options
Examples
--------
>>> mbs_data = robotran.MbsData("../dataR/ExampleProject.mbs")
>>> mbs_part = robotran.MbsPart(mbs_data)
>>> mbs_part.set_options(rowperm = 1, verbose = 0)
>>> mbs_part.get_options("rowperm", "verbose")
(1, 0)
>>> mbs_part.run()
"""
# Assing required user functions
self
.
__assign_user_fct__
()
self
.
mbs
.
__assign_user_fct__
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment