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_ = [
("buffersize", ctypes.c_int),
("realtime", ctypes.c_int),
("accelred", ctypes.c_int),
("flag_oneshot", ctypes.c_int),
("flag_compute_Qc", ctypes.c_int),
("compute_all_uxd", ctypes.c_int),
("compute_Qc", ctypes.POINTER(ctypes.c_int)),
......@@ -78,6 +79,11 @@ MbsDirdyn_c._fields_ = [
("user_buffer", ctypes.POINTER(MbsGrowingBuffer_c)),
("bufferNb", ctypes.c_int),
("savedArrays", ctypes.POINTER(ctypes.POINTER(ctypes.c_double))),
("SavePeriodCounter", ctypes.c_int)
# Pointer to integrator related functions are not exposed
\ No newline at end of file
("SavePeriodCounter", ctypes.c_int),
("flag_ongoing_jac_computation", ctypes.c_int),
# Access to integrator related functions are not implemented
("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 -*-
"""Set the arguments and return type of functions from MBsysC libraries."""
# Author: Robotran Team
# (c) Universite catholique de Louvain, 2019
import ctypes
......@@ -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.restype = ctypes.c_int
libmodules.mbs_fct_dirdyn.argtypes = [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.restype = None
......@@ -220,7 +220,15 @@ class MbsDirdyn(object):
error = libmodules.mbs_dirdyn_init(self.mbs_dirdyn_ptr, self.mbs.mbs_data_ptr)
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)
error = libmodules.mbs_fct_dirdyn(self.mbs_dirdyn_ptr.contents.tsim,
if (error >= 0 and self.get_options("save2file")):
# Results(buffer) memory is kept BUT FILES WILL BE WRITTEN LATER
......@@ -381,7 +389,8 @@ class MbsDirdyn(object):
- 0: results are not saved
default is 1
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'
respath: str
Path in which result file are saved. This is the full path or the
......@@ -422,6 +431,11 @@ class MbsDirdyn(object):
accelred: int
1 to use accelred, 0 otherwise.
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
If 1 it computes the forces/torques applied in each driven joints in
order to follow the specified trajectory. Otherwhise the forces/torques
......@@ -665,6 +679,7 @@ class MbsDirdyn(object):
'buffersize': {'convert': int, 'c_name': 'buffersize'},
'realtime': {'convert': int, 'c_name': 'realtime'},
'accelred': {'convert': int, 'c_name': 'accelred'},
'flag_oneshot': {'convert': int, 'c_name': 'flag_oneshot'},
'flag_compute_Qc': {'convert': int, 'c_name': 'flag_compute_Qc'},
'compute_all_uxd': {'convert': int, 'c_name': 'compute_all_uxd'},
'compute_Qc': {'convert': 'list or numpy.ndarray', 'c_name': 'compute_Qc'},
......@@ -746,7 +761,10 @@ class MbsDirdyn(object):
elif key == "resfilename":
address = self.mbs_dirdyn_ptr.contents.options.contents.resfilename
defaut = "dirdyn"
if self.get_options('flag_oneshot'):
defaut = "oneshot"
defaut = "dirdyn"
options.append(str_from_c_pointer(address, defaut))
elif key == "respath":
address = self.mbs_dirdyn_ptr.contents.options.contents.respath
......@@ -772,6 +790,8 @@ class MbsDirdyn(object):
elif key == "accelred":
elif key == "flag_oneshot":
elif key == "flag_compute_Qc":
elif key == "compute_all_uxd":
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