Commit d4ff5d94 authored by Olivier Lantsoght's avatar Olivier Lantsoght
Browse files

[MBsysPy][MbsDirdyn] Add Oneshot behavior.

parent aa51507a
...@@ -38,6 +38,7 @@ MbsDirdynOptions_c._fields_ = [ ...@@ -38,6 +38,7 @@ MbsDirdynOptions_c._fields_ = [
("buffersize", ctypes.c_int), ("buffersize", ctypes.c_int),
("realtime", ctypes.c_int), ("realtime", ctypes.c_int),
("accelred", ctypes.c_int), ("accelred", ctypes.c_int),
("flag_oneshot", ctypes.c_int),
("flag_compute_Qc", ctypes.c_int), ("flag_compute_Qc", ctypes.c_int),
("compute_all_uxd", ctypes.c_int), ("compute_all_uxd", ctypes.c_int),
("compute_Qc", ctypes.POINTER(ctypes.c_int)), ("compute_Qc", ctypes.POINTER(ctypes.c_int)),
...@@ -78,6 +79,11 @@ MbsDirdyn_c._fields_ = [ ...@@ -78,6 +79,11 @@ MbsDirdyn_c._fields_ = [
("user_buffer", ctypes.POINTER(MbsGrowingBuffer_c)), ("user_buffer", ctypes.POINTER(MbsGrowingBuffer_c)),
("bufferNb", ctypes.c_int), ("bufferNb", ctypes.c_int),
("savedArrays", ctypes.POINTER(ctypes.POINTER(ctypes.c_double))), ("savedArrays", ctypes.POINTER(ctypes.POINTER(ctypes.c_double))),
("SavePeriodCounter", ctypes.c_int) ("SavePeriodCounter", ctypes.c_int),
# Pointer to integrator related functions are not exposed ("flag_ongoing_jac_computation", ctypes.c_int),
] # Access to integrator related functions are not implemented
\ No newline at end of file ("integrator_struct", ctypes.c_void_p),
("initialize_integrator_ptr", ctypes.c_void_p),
("loop_integrator_ptr", ctypes.c_void_p),
("finish_integrator_ptr", ctypes.c_void_p),
]
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Set the arguments and return type of functions from MBsysC libraries.""" """Set the arguments and return type of functions from MBsysC libraries."""
# Author: Robotran Team
# (c) Universite catholique de Louvain, 2019 # (c) Universite catholique de Louvain, 2019
import ctypes import ctypes
...@@ -156,6 +157,11 @@ libmodules.mbs_dirdyn_init.restype = ctypes.c_int ...@@ -156,6 +157,11 @@ libmodules.mbs_dirdyn_init.restype = ctypes.c_int
libmodules.mbs_dirdyn_loop.argtypes = [ctypes.POINTER(MbsDirdyn_c), ctypes.POINTER(MbsData_c)] libmodules.mbs_dirdyn_loop.argtypes = [ctypes.POINTER(MbsDirdyn_c), ctypes.POINTER(MbsData_c)]
libmodules.mbs_dirdyn_loop.restype = ctypes.c_int libmodules.mbs_dirdyn_loop.restype = ctypes.c_int
libmodules.mbs_fct_dirdyn.argtypes = [ctypes.c_float, ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(MbsData_c), ctypes.POINTER(MbsDirdyn_c)]
libmodules.mbs_fct_dirdyn.restype = ctypes.c_int
libmodules.mbs_dirdyn_finish.argtypes = [ctypes.POINTER(MbsDirdyn_c), ctypes.POINTER(MbsData_c)] libmodules.mbs_dirdyn_finish.argtypes = [ctypes.POINTER(MbsDirdyn_c), ctypes.POINTER(MbsData_c)]
libmodules.mbs_dirdyn_finish.restype = None libmodules.mbs_dirdyn_finish.restype = None
......
...@@ -220,7 +220,15 @@ class MbsDirdyn(object): ...@@ -220,7 +220,15 @@ class MbsDirdyn(object):
self.set_options(save2file=1) self.set_options(save2file=1)
error = libmodules.mbs_dirdyn_init(self.mbs_dirdyn_ptr, self.mbs.mbs_data_ptr) error = libmodules.mbs_dirdyn_init(self.mbs_dirdyn_ptr, self.mbs.mbs_data_ptr)
if (error >= 0): if (error >= 0):
error = libmodules.mbs_dirdyn_loop(self.mbs_dirdyn_ptr, self.mbs.mbs_data_ptr) if not self.get_options('flag_oneshot'):
error = libmodules.mbs_dirdyn_loop(self.mbs_dirdyn_ptr, self.mbs.mbs_data_ptr)
else:
error = libmodules.mbs_fct_dirdyn(self.mbs_dirdyn_ptr.contents.tsim,
self.mbs_dirdyn_ptr.contents.y,
self.mbs_dirdyn_ptr.contents.yd,
self.mbs_dirdyn_ptr,
self.mbs.mbs_data_ptr
)
if (error >= 0 and self.get_options("save2file")): if (error >= 0 and self.get_options("save2file")):
# Results(buffer) memory is kept BUT FILES WILL BE WRITTEN LATER # Results(buffer) memory is kept BUT FILES WILL BE WRITTEN LATER
...@@ -381,7 +389,8 @@ class MbsDirdyn(object): ...@@ -381,7 +389,8 @@ class MbsDirdyn(object):
- 0: results are not saved - 0: results are not saved
default is 1 default is 1
resfilename: str resfilename: str
The keyword used for determining the name of result files. The keyword used for determining the name of result files. The default
value is set to 'oneshot' (instead of 'dirdyn') if 'flag_oneshot' is True.
default is 'dirdyn' default is 'dirdyn'
respath: str respath: str
Path in which result file are saved. This is the full path or the Path in which result file are saved. This is the full path or the
...@@ -422,6 +431,11 @@ class MbsDirdyn(object): ...@@ -422,6 +431,11 @@ class MbsDirdyn(object):
accelred: int accelred: int
1 to use accelred, 0 otherwise. 1 to use accelred, 0 otherwise.
default is 0 default is 0
flag_oneshot: int
Set to 1 to compute the derivative function only once (no time integration).
Then default resfilename is set to 'oneshot'.
The time is the value found in the option t0 (used by user functions).
default is 0
flag_compute_Qc: int flag_compute_Qc: int
If 1 it computes the forces/torques applied in each driven joints in If 1 it computes the forces/torques applied in each driven joints in
order to follow the specified trajectory. Otherwhise the forces/torques order to follow the specified trajectory. Otherwhise the forces/torques
...@@ -665,6 +679,7 @@ class MbsDirdyn(object): ...@@ -665,6 +679,7 @@ class MbsDirdyn(object):
'buffersize': {'convert': int, 'c_name': 'buffersize'}, 'buffersize': {'convert': int, 'c_name': 'buffersize'},
'realtime': {'convert': int, 'c_name': 'realtime'}, 'realtime': {'convert': int, 'c_name': 'realtime'},
'accelred': {'convert': int, 'c_name': 'accelred'}, 'accelred': {'convert': int, 'c_name': 'accelred'},
'flag_oneshot': {'convert': int, 'c_name': 'flag_oneshot'},
'flag_compute_Qc': {'convert': int, 'c_name': 'flag_compute_Qc'}, 'flag_compute_Qc': {'convert': int, 'c_name': 'flag_compute_Qc'},
'compute_all_uxd': {'convert': int, 'c_name': 'compute_all_uxd'}, 'compute_all_uxd': {'convert': int, 'c_name': 'compute_all_uxd'},
'compute_Qc': {'convert': 'list or numpy.ndarray', 'c_name': 'compute_Qc'}, 'compute_Qc': {'convert': 'list or numpy.ndarray', 'c_name': 'compute_Qc'},
...@@ -746,7 +761,10 @@ class MbsDirdyn(object): ...@@ -746,7 +761,10 @@ class MbsDirdyn(object):
options.append(self.mbs_dirdyn_ptr.contents.options.contents.save2file) options.append(self.mbs_dirdyn_ptr.contents.options.contents.save2file)
elif key == "resfilename": elif key == "resfilename":
address = self.mbs_dirdyn_ptr.contents.options.contents.resfilename address = self.mbs_dirdyn_ptr.contents.options.contents.resfilename
defaut = "dirdyn" if self.get_options('flag_oneshot'):
defaut = "oneshot"
else:
defaut = "dirdyn"
options.append(str_from_c_pointer(address, defaut)) options.append(str_from_c_pointer(address, defaut))
elif key == "respath": elif key == "respath":
address = self.mbs_dirdyn_ptr.contents.options.contents.respath address = self.mbs_dirdyn_ptr.contents.options.contents.respath
...@@ -772,6 +790,8 @@ class MbsDirdyn(object): ...@@ -772,6 +790,8 @@ class MbsDirdyn(object):
options.append(self.mbs_dirdyn_ptr.contents.options.contents.realtime) options.append(self.mbs_dirdyn_ptr.contents.options.contents.realtime)
elif key == "accelred": elif key == "accelred":
options.append(self.mbs_dirdyn_ptr.contents.options.contents.accelred) options.append(self.mbs_dirdyn_ptr.contents.options.contents.accelred)
elif key == "flag_oneshot":
options.append(self.mbs_dirdyn_ptr.contents.options.contents.flag_oneshot)
elif key == "flag_compute_Qc": elif key == "flag_compute_Qc":
options.append(self.mbs_dirdyn_ptr.contents.options.contents.flag_compute_Qc) options.append(self.mbs_dirdyn_ptr.contents.options.contents.flag_compute_Qc)
elif key == "compute_all_uxd": elif key == "compute_all_uxd":
......
Markdown is supported
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