blockfactory
blockfactory copied to clipboard
Implement support for stateful systems
This is probably a long term goal, but for now let's collect some possible basic steps:
- [ ] Add support for reading continuous state in
BlockInformation
- [ ] Add support for reading and writing discrete state in
BlockInformation
- [ ] Implement support for reading continuous state in
SimulinkBlockInformation
(probably usingssGetContStates
) - [ ] Implement support for reading discrete state in
SimulinkBlockInformation
(probably usingssGetDiscStates
) - [ ] Implement support for reading continuous state in
CoderBlockInformation
- [ ] Implement support for reading and writing discrete state in
CoderBlockInformation
- [ ] Correctly implement
mdlDerivatives
in the BlockFactory S-Function: https://github.com/robotology/blockfactory/blob/78a8723dd7018f44e6ecc646f5b32868a9fe1f6c/sources/Mex/src/BlockFactory.cpp#L317 - [ ] Permit to specify that a (input) port of the block is not direct feed-through (see
ssSetInputPortDirectFeedThrough
and https://drake.mit.edu/doxygen_cxx/classdrake_1_1systems_1_1_system.html thedrake::systems::System<T>::xxxDirectFeedthrough
methods for an inspiration related to the corresponding Drake API . At the moment this is hardcoded at Simulink level in https://github.com/robotology/blockfactory/blob/78a8723dd7018f44e6ecc646f5b32868a9fe1f6c/sources/Mex/src/SimulinkBlockInformationImpl.cpp#L173 .
For the discrete state, it is also important to specify the sample time of the period update connected to the discrete state update. See https://it.mathworks.com/help/simulink/sfg/sample-times-cpp.html#f4-33929 for a description of this concept in the Simulink docs, and https://drake.mit.edu/doxygen_cxx/classdrake_1_1systems_1_1_leaf_system.html#a262f71637a37127840acefca3bda8897 for the related API in Drake's System API.
For the discrete state, it is also important to specify the sample time of the period update connected to the discrete state update.
Related to that, for properly describing this in FMUs it is necessary to wait for FMI 3. See https://github.com/modelica/fmi-standard/issues/353 and http://www.ep.liu.se/ecp/132/057/ecp17132507.pdf .
Still related to stateful systems, it is relevant to mention that simStateCompliance should be properly set in Simulink: https://github.com/robotology/blockfactory/blob/f8a363e595fb748d313f3785f5a94d831a3ee796/sources/Simulink/src/BlockFactory.cpp#L175 .
At the moment, it is set to USE_CUSTOM_SIM_STATE
. This means (see https://it.mathworks.com/help/simulink/sfg/s-function-compliance-with-the-simstate.html) that the S-Function "has mdlGetSimState and mdlSetSimState methods", that are not implemented in the existing BlockFactory S-Function.
That part of S-Function code is a very old heritage (from first versions of WBI-Toolbox I think). All of them would need a refreshing, not only this one.
cc @fjandrad