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
86d21b79
Commit
86d21b79
authored
Sep 06, 2019
by
Louis Beauloye
Browse files
[Ctypes] replace extra equil variable
parent
c5a3f413
Changes
2
Hide whitespace changes
Inline
Side-by-side
ExampleProjects/TutorialProjects/analysisModules/equilibrium_CI/workR/main_MBsysPy.py
View file @
86d21b79
...
...
@@ -107,7 +107,8 @@ mbs_equil.print_equil()
mbs_data
.
mbs_reset_data
()
mbs_data
.
set_qa
(
mbs_data
.
joint_id
[
"R2_pendulum"
])
mbs_equil
=
Robotran
.
MbsEquil
(
mbs_data
)
mbs_equil
.
add_extra_variable
(
mbs_data
.
Qa
,
mbs_data
.
joint_id
[
"R2_pendulum"
])
mbs_equil
.
add_extra_variable_um
(
"mylink"
,
"L0"
)
mbs_equil
.
replace_extra_variable
(
mbs_data
.
Qa
,
mbs_data
.
joint_id
[
"R2_pendulum"
],
1
)
mbs_equil
.
set_options
(
senstol
=
1e-6
,
compute_uxd
=
0
,
resfilename
=
"equil6"
)
mbs_equil
.
set_options
(
grad_lpk
=
1
)
mbs_equil
.
run
()
...
...
MBsysC/mbs_interface/MBsysPy/mbsyspy/mbs_equil.py
View file @
86d21b79
...
...
@@ -47,7 +47,7 @@ from ..mbsysc_loader.callback import mbs_invdyna_wrap
#==============================================================================
# Global parameter of the current module
#==============================================================================
__DEBUG__
=
Tru
e
__DEBUG__
=
Fals
e
__MODULE_DIR__
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
...
...
@@ -447,9 +447,9 @@ class MbsEquil(object):
----------
ptr : ndarray
Array containing the extra variable
Array containing the extra variable
to add to the equilibrium variables
index : int
Index in ptr of the extra variable
Index in ptr of the extra variable
to add to the equilibrium variables
"""
if
self
.
get_options
(
"nxe"
):
...
...
@@ -459,7 +459,7 @@ class MbsEquil(object):
return
address
=
ptr
.
ctypes
.
data
+
ctypes
.
sizeof
(
ctypes
.
c_double
)
*
index
if
ptr
.
ctypes
.
data
==
self
.
mbs
.
q
.
ctypes
.
data
:
print
(
">>EQUIL>>
variable
exchange : Warning ! Generalized coordinates have to be used with caution as ex
change
variables"
)
print
(
">>EQUIL>>
extra
exchange : Warning ! Generalized coordinates have to be used with caution as ex
tra
variables"
)
if
len
(
self
.
addition_list
)
==
0
:
self
.
addition_list
=
[
address
]
...
...
@@ -484,9 +484,9 @@ class MbsEquil(object):
----------
user_model : str
Name of the user model to
be added
Name of the user model to
add to the equilibrium variables
param : str
Parameter of the user model to
be added
Parameter of the user model to
add to the equilibrium variables
"""
if
self
.
get_options
(
"nxe"
):
...
...
@@ -596,8 +596,63 @@ class MbsEquil(object):
print
(
">>EQUIL>> variable exchange : There is no exchange variable at this index :"
+
str
(
id_exchanged
))
else
:
self
.
exchange_list
[
id_exchanged
-
1
][
0
]
=
ptr
.
ctypes
.
data
+
ctypes
.
sizeof
(
ctypes
.
c_double
)
*
index
def
replace_extra_variable
(
self
,
ptr
,
index
,
id_extra
):
""" Replace an existing extra variable with another one
This function can be called between two 'MbsEquil::run()' as it
does not change the number of equilibrium variables
Parameters
----------
ptr : ndarray
Array containing the extra variable
index : int
Index in ptr of the extra variable
id_exchanged : int
Index in the list of extra variable of the variable to be
replaced
"""
if
ptr
.
ctypes
.
data
==
self
.
mbs
.
q
.
ctypes
.
data
:
print
(
">>EQUIL>> extra exchange : Warning generalized coordinates have to be used with caution as extra variables"
)
if
id_extra
>
len
(
self
.
addition_list
)
or
id_extra
<=
0
:
print
(
">>EQUIL>> extra exchange : There is no extra variable at this index :"
+
str
(
id_extra
))
else
:
self
.
addition_list
[
id_extra
-
1
]
=
ptr
.
ctypes
.
data
+
ctypes
.
sizeof
(
ctypes
.
c_double
)
*
index
def
replace_extra_variable_um
(
self
,
user_model
,
param
,
id_extra
):
""" Replace an existing extra variable with a user model
This function can be called between two 'MbsEquil::run()' as it
does not change the number of equilibrium variables
Parameters
----------
user_model : str
Name of the user model to add to the equilibrium variables
param : str
Parameter of the user model to add to the equilibrium variables
id_exchanged : int
Index in the list of extra variable of the variable to be
replaced
"""
if
self
.
mbs
.
user_model
[
user_model
].
_type
[
param
]
!=
1
and
self
.
mbs
.
user_model
[
user_model
].
_type
[
param
]
!=
7
:
print
(
">>EQUIL>> extra exchange : This function does not handle this type of user model (only float and int)"
)
return
if
id_extra
>
len
(
self
.
addition_list
)
or
id_extra
<=
0
:
print
(
">>EQUIL>> extra exchange : There is no extra variable at this index :"
+
str
(
id_extra
))
else
:
self
.
addition_list
[
id_extra
-
1
][
0
]
=
self
.
mbs
.
user_model
[
user_model
].
__getarray__
(
param
)[
0
].
ctypes
.
data
def
replace_exchange_um
(
self
,
user_model
,
param
,
id_exchanged
):
""" Replace an existing exchanged variable with a user model
...
...
@@ -778,12 +833,6 @@ class MbsEquil(object):
self
.
mbs_equil_ptr
.
contents
.
options
.
contents
.
visualize
=
value
elif
key
==
"clearmbsglobal"
:
self
.
mbs_equil_ptr
.
contents
.
options
.
contents
.
clearmbsglobal
=
value
elif
key
==
"nxe"
:
print
(
">>EQUIL>> Option "
+
key
+
" not yet implemented in python"
)
elif
key
==
"xe_ptr"
:
print
(
">>EQUIL>> Option "
+
key
+
" not yet implemented in python"
)
elif
key
==
"xe_index"
:
print
(
">>EQUIL>> Option "
+
key
+
" not yet implemented in python"
)
elif
key
==
"save_anim"
:
self
.
mbs_equil_ptr
.
contents
.
options
.
contents
.
save_anim
=
value
elif
key
==
"framerate"
:
...
...
@@ -868,10 +917,6 @@ class MbsEquil(object):
options
.
append
(
self
.
mbs_equil_ptr
.
contents
.
options
.
contents
.
nquch
)
elif
key
==
"nxe"
:
options
.
append
(
self
.
mbs_equil_ptr
.
contents
.
options
.
contents
.
nxe
)
elif
key
==
"xe_ptr"
:
print
(
">>EQUIL>> Option "
+
key
+
" not yet implemented in python"
)
elif
key
==
"xe_index"
:
print
(
">>EQUIL>> Option "
+
key
+
" not yet implemented in python"
)
elif
key
==
"save_anim"
:
options
.
append
(
self
.
mbs_equil_ptr
.
contents
.
options
.
contents
.
save_anim
)
elif
key
==
"framerate"
:
...
...
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