blockfactory icon indicating copy to clipboard operation
blockfactory copied to clipboard

Implement support for stateful systems

Open traversaro opened this issue 6 years ago • 5 comments

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 using ssGetContStates)
  • [ ] Implement support for reading discrete state in SimulinkBlockInformation (probably using ssGetDiscStates)
  • [ ] 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 the drake::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 .

traversaro avatar Dec 23 '18 00:12 traversaro

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.

traversaro avatar Dec 26 '18 00:12 traversaro

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 .

traversaro avatar Dec 30 '18 09:12 traversaro

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.

traversaro avatar Jan 20 '19 23:01 traversaro

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.

diegoferigo avatar Jan 21 '19 10:01 diegoferigo

cc @fjandrad

diegoferigo avatar Nov 16 '19 09:11 diegoferigo