Commit 47f79f5e authored by Olivier Lantsoght's avatar Olivier Lantsoght
Browse files

[Ctypes] Mainly doc

parent 90802c82
......@@ -943,6 +943,21 @@ class MbsData(object):
libutilities.mbs_set_qv(self.mbs_data_ptr, index)
else:
libutilities.mbs_set_qv(self.mbs_data_ptr, indices)
def set_qdriven(self, indices):
"""
Set the specified joints as driven.
Parameters
----------
indices : int, list or numpy.ndarray
The ids of the joints to set as driven.
"""
if isinstance(indices,(list,np.ndarray)):
for index in indices:
libutilities.mbs_set_qdriven(self.mbs_data_ptr, index)
else:
libutilities.mbs_set_qdriven(self.mbs_data_ptr, indices)
def set_qa(self, indices):
"""
......
......@@ -56,7 +56,25 @@ __MODULE_DIR__ = os.path.dirname(os.path.abspath(__file__))
#==============================================================================
class MbsEquil(object):
"""
Class of the Equilibrium (static or quasi-static) module.
Attributes
----------
results : MbsResultEquil
Instance of MbsResultEquil (dedicated to equilibrium module) containing
the results of the numerical analysis.
Examples
--------
>>> mbs_data = MBsysPy.MbsData("../dataR/ExampleProject.mbs")
>>> mbs_equil = MBsysPy.MbsEquil(mbs_data)
>>> mbs_equil.set_options(equitol = 1e-4)
>>> mbs_equil.get_options(equitol)
0.0001
>>> results = mbs_equil.run()
"""
def __init__(self, mbs,user_path=None, symbolic_path=None):
if __DEBUG__ : print( "DEBUG>> Creating MbsEquil struct for "+mbs.mbs_name+"' MBS.")
self.mbs_equil_ptr = libmodules.mbs_new_equil(mbs.mbs_data_ptr)
......@@ -66,13 +84,6 @@ class MbsEquil(object):
#Test
if __DEBUG__ :
print( "DEBUG>> MbsEquil created.")
print( " >> aux->NRerr (-): ", self.mbs_equil_ptr.contents.aux.contents.NRerr)
print( " >> aux->nquc (-): ", self.mbs_equil_ptr.contents.aux.contents.nquc)
print( " >> aux->M[1:3][1:3]: ",
self.mbs_equil_ptr.contents.aux.contents.M[1][1],
self.mbs_equil_ptr.contents.aux.contents.M[1][2],
self.mbs_equil_ptr.contents.aux.contents.M[2][1],
self.mbs_equil_ptr.contents.aux.contents.M[2][2])
# Path to user function used by partitionning module
self.user_path = self.mbs.user_path
if not (user_path==None):
......
......@@ -48,12 +48,11 @@ __MODULE_DIR__ = os.path.dirname(os.path.abspath(__file__))
class MbsPart(object):
"""
Class of the coordinate partitioning module
Class of the coordinate partitioning module.
Attributes
----------
n_qu : int
Number of independent variable needed.
n_qv: int
......@@ -65,8 +64,37 @@ class MbsPart(object):
q_closed : ndarray
Array with the generalized coordinate in closed configuration
(constraints solved)
Examples
--------
>>> mbs_data = MBsysPy.MbsData("../dataR/ExampleProject.mbs")
>>> mbs_data.set_qv(2)
>>> mbs_part = MBsysPy.MbsPart(mbs_data)
>>> mbs_part.set_options(rowperm=1)
>>> mbs_part.run()
"""
def __init__(self, mbs, user_path=None, symbolic_path=None):
"""
Create an instance of the MbsPart class for the provided MbsData instance.
Parameters
----------
mbs : MbsData
Instance of MbsData related to the analysis.
user_path : str or None, optionnal
The path to the folder containing the user functions. If not provided
('None') the path is retrieved from the MbsData instance 'mbs'.
default is None
symbolic_path : str or None, optionnal
The path to the folder containing the symbolic functions. If not
provided ('None') the path is retrieved from the MbsData instance 'mbs'.
default is None
Returns
-------
A MbsPart instance.
"""
if __DEBUG__ : print( "DEBUG>> Creating MbsPart struct for "+mbs.mbs_name+"' MBS.")
self.mbs_part_ptr = libmodules.mbs_new_part(mbs.mbs_data_ptr)
if __DEBUG__ : print( "DEBUG>> MbsPartmbs_ structure loaded")
......@@ -125,15 +153,20 @@ class MbsPart(object):
def __load_user_fct__(self, user_path):
"""
Load user function where some args depend on MbsPart module.
Load the user functions in which some of the arguments are
dependent of MbsPart module instance. The functions will be
assigned to the MbsData instance when the 'run' function is called
and unassigned at the end.
The loader user functions are :
- user_cons_hJ (from cons_hJ.py)
Load user function where some args depend on MbsPart module.
Load the user functions in which some of the arguments are
dependent of MbsPart module instance. The functions will be
assigned to the MbsData instance when the 'run' function is called
and unassigned at the end.
The loader user functions are :
- user_cons_hJ (from cons_hJ.py)
Parameters
----------
user_path : str
The path to the folder containing the user functions.
"""
template_path = os.path.join(__MODULE_DIR__,'../templates/user')
......@@ -149,15 +182,20 @@ class MbsPart(object):
def __load_symbolic_fct__(self, symbolic_path):
"""
Load symbolic function where some args depend on MbsPart module.
Load the symb functions in which some of the arguments are
dependent of MbsPart module instance. The functions will be
assigned to the MbsData instance when the 'run' function is called
and unassigned at the end.
The loader user functions are :
- cons_hJ (from mbs_cons_hJ_MBSNAME.py)
Load symbolic function where some args depend on MbsPart module.
Load the symb functions in which some of the arguments are
dependent of MbsPart module instance. The functions will be
assigned to the MbsData instance when the 'run' function is called
and unassigned at the end.
The loader user functions are :
- cons_hJ (from mbs_cons_hJ_MBSNAME.py)
Parameters
----------
symbolic_path : str
The path to the folder containing the symbolic functions.
"""
mbs_name = self.mbs.mbs_name
template_path = os.path.join(__MODULE_DIR__,'../templates/symbolic')
......@@ -174,9 +212,9 @@ class MbsPart(object):
def __assign_user_fct__(self):
"""
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
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.
"""
......@@ -187,9 +225,9 @@ class MbsPart(object):
def __assign_symbolic_fct__(self):
"""
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
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))
......@@ -210,14 +248,12 @@ class MbsPart(object):
fun(__h,__Jac,self.mbs)
def __del__(self):
libmodules.mbs_delete_part(self.mbs_part_ptr)
if __DEBUG__ : print("DEBUG>> MbsPart pointer deleted")
def __unassign_user_fct__(self):
"""
Unassign user function where some args depend on MbsPart module.
Unassign user function where some args depend on MbsPart module.
"""
self.ptrs_to_user_fcts = {}
self.mbs.user_cons_hJ = None
......@@ -227,8 +263,7 @@ class MbsPart(object):
def __unassign_symbolic_fct__(self):
"""
Unassign symbolic function where some args depend on MbsPart module.
Unassign symbolic function where some args depend on MbsPart module.
"""
self.ptrs_to_symb_fcts = {}
self.mbs.mbs_cons_hJ = None
......@@ -238,21 +273,10 @@ class MbsPart(object):
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()
Run a coordinate partitioning.
Options can be setted with the function 'set_options()'
Options can be retrieved with the function 'get_options()'
"""
# Assing required user functions
if self.mbs.opt_load_c < 2:
......@@ -277,35 +301,30 @@ class MbsPart(object):
def set_options(self, **kwargs):
"""
Set the specified options for Part module
Set the specified options for Part module.
Parameters
----------
rowperm : int
1 to allow line permutation
0 otherwise
defaut = 0
1 to allow line permutation, 0 to forbid it.
defaut is 0
visualise : int
no = 0
yes = 1
defaut = 0
drivers : int
no = 0
yes = 1
defaut = 0
Unused but 1 stand for yes, 0 for no.
defaut is 0
drivers : int
Unused but 1 stand for yes, 0 for no.
defaut is 0
verbose : int
1 to get print indications related partitioning module
0 otherwise
defaut = 1
clearmbsglobal : int
inout = 1
out = 2
none = 3
all = 4
defaut = 1
Set to 1 to get messages related to partitioning module. Set to 0
to disable message.
defaut is 1
clearmbsglobal : int
Unused, but:
- 1 is for inout
- 2 is for out
- 3 is for none
- 4 is for all
defaut is 1
"""
for key, value in kwargs.items():
if key == "rowperm":
......@@ -323,17 +342,15 @@ class MbsPart(object):
def get_options(self, *args):
"""
Get the specified options for Part module
Get the specified options for Part module.
Parameters
----------
The different options specifed in the documentation of set_options
The different options specifed in the documentation of 'set_options()'.
Returns
-------
The value of the different options specifed in the documentation of set_options
The value of the required options.
"""
options = []
......@@ -380,42 +397,6 @@ class MbsPart(object):
def q_closed(self):
return self.__q_closed
@property
def rowperm(self):
return self.mbs_part_ptr.contents.options.rowperm
@rowperm.setter
def rowperm(self, value):
self.mbs_part_ptr.contents.options.rowperm = value
@property
def visualise(self):
return self.mbs_part_ptr.contents.options.visualise
@visualise.setter
def visualise(self, value):
self.mbs_part_ptr.contents.options.visualise = value
@property
def drivers(self):
return self.mbs_part_ptr.contents.options.drivers
@property
def verbose(self):
return self.mbs_part_ptr.contents.options.verbose
@verbose.setter
def verbose(self, value):
self.mbs_part_ptr.contents.options.verbose = value
@property
def clearmbsglobal(self):
return self.mbs_part_ptr.contents.options.clearmbsglobal
@clearmbsglobal.setter
def clearmbsglobal(self, value):
self.mbs_part_ptr.contents.options.clearmbsglobal = value
@property
def mbs_filename(self):
return self.mbs.mbs_filename
......
......@@ -36,7 +36,14 @@ __DEBUG__ = True
class MbsSensor(object):
"""
Sensor are used to compute fields of a point on the multibody system.
Sensor can be computed in pure Python or computed by Python but the memory
being allocated by the C-library or computed (and allocated) by the c-library.
This class can be used for:
- Sensor : retrived data of a point of the system
- GenSensor : retrive data of the origin of any body of the system
- ForceSensor : retrieve data of a point of the sensor and apply a force on it
Attributes
----------
......@@ -63,12 +70,14 @@ class MbsSensor(object):
J[1:njoint,1:7]=(d velocity)/(d q)
id_ : int or None
The ID of the sensor on the system. It is required to update the sensor
values without giving the id to the method `sensor` or `gensensor` (
both having an optionnal parameter `id_`).
values without giving the id to the method `sensor` or `gensensor` (both
having an optionnal parameter `id_`).
"""
def __init__(self, mbs, id_=None, sensor_ptr=None):
"""
The sensor can be linked with C-memory or being in pure Python.
Create an instance of the MbsSensor class.
The sensor can be linked with C-memory (sensor_ptr) or being in pure Python.
Parameters
----------
......@@ -79,14 +88,13 @@ class MbsSensor(object):
sensor_ptr : ctypes.POINTER(MbsSensor_c), optionnal
A pointer to an existing strucure of MbsSensor_c. If provided the
Python instance will share its memory with the C structure.
"""
self.__mbs_data = mbs
self.id = id_
if (sensor_ptr is None) and (mbs.opt_load_c==0):
# Sensor is fully computed and allocated in Python
self.__sensor_ptr = None
# Sensor created in Python
self.__python = True
self.__P = np.array([3,0.,0.,0.])
......@@ -105,10 +113,12 @@ class MbsSensor(object):
# Binding the sensor with a C-memory
self.__python = False
if sensor_ptr is None:
# The sensor must be allocated in the C-library
self.__sensor_ptr = libmodules.mbs_new_sensor(self.__mbs_data.mbs_data_ptr)
libmodules.allocate_sensor(self.__sensor_ptr, mbs.njoint)
libmodules.init_sensor(self.__sensor_ptr, mbs.njoint)
else:
# The sensor already exists in the C-library
self.__sensor_ptr = ctypes.cast(sensor_ptr, ctypes.POINTER(MbsSensor_c))
self.__P = np.ctypeslib.as_array(self.__sensor_ptr.contents.P, (4,))
......@@ -122,6 +132,9 @@ class MbsSensor(object):
def assign_to_C(self,sensor):
"""
Reassign a python sensor to an existing C MbsSensor structure.
If the sensor was already allocated by the C-library, it will not be
binded again.
Parameters
----------
......@@ -145,7 +158,7 @@ class MbsSensor(object):
def sensor(self, id_=None):
"""
Update the field of the sensor.
Update the fields of the sensor.
Compute all field of the specified sensor. The sensors have been
defined by the user on the MBS in the MBsysPAD interface.
......@@ -157,8 +170,8 @@ class MbsSensor(object):
Notes
-----
If 'id_' is not set on the sensor instance, the first sensor is
computed.
If 'id_' is not set on the sensor instance the first sensor is
computed. However a warning is generated.
See Also
--------
......@@ -166,7 +179,7 @@ class MbsSensor(object):
"""
if id_ == None:
if self.id == None:
print("Sensor id was not defined. Using default id (=1)")
print(">> Warning >> Sensor id was not defined. Using default id (=1)")
id_ = 1
else:
id_ = self.id
......@@ -177,10 +190,10 @@ class MbsSensor(object):
def gensensor(self, id_=None):
"""
Update the field of the sensor.
Update the fields of the sensor.
Compute all field of the specified sensor. The sensors were
automatically defined at the origin of each body of the MBS.
Compute all field of the specified sensor. The sensors were automatically
defined at the origin of each body of the MBS.
Parameters
----------
......@@ -189,8 +202,8 @@ class MbsSensor(object):
Notes
-----
If 'id_' is not set on the sensor instance, the first sensor is
computed.
If 'id_' is not set on the sensor instance, the first body is considered.
However a warning is generated.
See Also
--------
......@@ -198,7 +211,8 @@ class MbsSensor(object):
"""
if id_ == None:
if self.id == None:
print("Sensor id was not defined. Using default id (=1)")
print(">> Warning >> Body id was not defined for gensensor."
"Using default id (=1).")
id_ = 1
else:
id_ = self.id
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment