|
| 1 | +/* |
| 2 | + ISC License |
| 3 | +
|
| 4 | + Copyright (c) 2025, Autonomous Vehicle Systems Lab, University of Colorado at Boulder |
| 5 | +
|
| 6 | + Permission to use, copy, modify, and/or distribute this software for any |
| 7 | + purpose with or without fee is hereby granted, provided that the above |
| 8 | + copyright notice and this permission notice appear in all copies. |
| 9 | +
|
| 10 | + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 11 | + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 12 | + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 13 | + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 14 | + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 15 | + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 16 | + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 | +
|
| 18 | + */ |
| 19 | +%module(directors="1",threads="1") StatefulSysModel |
| 20 | +%{ |
| 21 | + #include "StatefulSysModel.h" |
| 22 | +%} |
| 23 | + |
| 24 | +%pythoncode %{ |
| 25 | +import sys |
| 26 | +import traceback |
| 27 | +from Basilisk.architecture.swig_common_model import * |
| 28 | +%} |
| 29 | + |
| 30 | +%include "architecture/utilities/bskLogging.h" |
| 31 | +%import "architecture/_GeneralModuleFiles/py_sys_model.i" |
| 32 | + |
| 33 | +// We don't need to construct the DynParamRegisterer on the Python side |
| 34 | +%ignore DynParamRegisterer::DynParamRegisterer; |
| 35 | + |
| 36 | +%feature("director") StatefulSysModel; |
| 37 | +%feature("pythonappend") StatefulSysModel::StatefulSysModel %{ |
| 38 | + self.__super_init_called__ = True%} |
| 39 | +%rename("_StatefulSysModel") StatefulSysModel; |
| 40 | +%include "StatefulSysModel.h" |
| 41 | + |
| 42 | +%template(registerState) DynParamRegisterer::registerState<StateData, true>; |
| 43 | + |
| 44 | +%pythoncode %{ |
| 45 | +class StatefulSysModel(_StatefulSysModel, metaclass=Basilisk.architecture.sysModel.SuperInitChecker): |
| 46 | + bskLogger: BSKLogger = None |
| 47 | + |
| 48 | + def __init_subclass__(cls): |
| 49 | + # Make it so any exceptions in UpdateState and Reset |
| 50 | + # print any exceptions before returning control to |
| 51 | + # C++ (at which point exceptions will crash the program) |
| 52 | + cls.UpdateState = Basilisk.architecture.sysModel.logError(cls.UpdateState) |
| 53 | + cls.Reset = Basilisk.architecture.sysModel.logError(cls.Reset) |
| 54 | + cls.registerStates = Basilisk.architecture.sysModel.logError(cls.registerStates) |
| 55 | +%} |
0 commit comments