Karana.Models#
General models used in a variety of simulations.
Submodules#
Attributes#
Classes#
BaseClass for the model parameters of Python models. |
|
Class indicating there are no model params. |
|
Class indicating there is no model scratch. |
|
Class indicating there are no model discrete states. |
|
Class indicating there are no model continuous states. |
|
Base class for all Python models. |
|
This BaseKModel serves as the base for all models. It implements |
|
A base class for continuous model states. Derive from this and add any |
|
A base class for discrete model states. Derive from this and add any |
|
A base class for continuous model states. Derive from this and add any |
|
A base class for discrete model states. Derive from this and add any |
|
A scratchpad to store model information. This is primarily used for |
|
Members: |
|
KModel<T,P,Sc,S,C> uses the curiously recurring template pattern |
|
Limits the generalized force that can be applied to a subhinge. |
|
The DataLogger model updates the visualization at each postHop. |
|
Parameters for the DataLogger model. |
|
The DataPlotter model updates the visualization at each postHop. |
|
Parameters for the DataPlotter model. |
|
The GraphicalSceneMovie model updates the visualization at each |
|
Parameters for the GraphicalSceneMovie model. |
|
Apply uniform gravitational acceleration to each body in the provided |
|
Common GravityInterface used for computing gravity with various |
|
The output of a GravityInterface. |
|
Simple PID controller model. |
|
Parameters for the PID model. |
|
Model that adds joint limits to a pin hinge. |
|
Parameters for the PinJointLimits model. |
|
A GravityInterface implementation for point-mass gravity. |
|
The ProjectConstraintError model updates the visualization at each |
|
Parameters for the ProjectConstraintError model. |
|
Adds a spring-damper between two nodes. |
|
Parameters for the SpringDamper model. |
|
Scratch variables for the SpringDamper model. |
|
Limits the generalized force that can be applied to a subhinge. |
|
Parameters for the SubhingeForceLimits model. |
|
Adds a spring damper to the provided subhinge. |
|
Parameters for the SubhingeSpringDamper model. |
|
Limits sim speed to a multiple of real time. |
|
The TimeDisplay model updates the visualization at each postHop. |
|
Parameters for the TimeDisplay KModel. |
|
A GravityInterface implementation for uniform gravity. |
|
The UpdateProxyScene model updates the visualization at each postHop. |
|
Model applying penalty contact forces to collisions from the provided |
|
Package Contents#
- class Karana.Models.KModelParams(/, **data: Any)#
Bases:
Karana.KUtils.DataStruct.DataStructBaseClass for the model parameters of Python models.
For a new model parameter class, simply derive from this class and add class variables just like you would do for any other DataStruct. Users should override the isReady if applicable to ensure that all model parameters have been defined.
- dumpString(prefix: str, options: Karana.Core.DumpOptionsBase | None = None) str[source]#
Dump the parameters as a string.
- Parameters:
prefix (str) – The prefix for the string.
options (_DumpOptionsBase | None) – Options for the string.
- Returns:
The parameters as a string.
- Return type:
str
- class Karana.Models.NoParams(/, **data: Any)#
Bases:
KModelParamsClass indicating there are no model params.
- class Karana.Models.NoScratch#
Bases:
KModelScratchClass indicating there is no model scratch.
- class Karana.Models.NoDiscreteStates#
Bases:
KModelDiscreteStatesClass indicating there are no model discrete states.
- class Karana.Models.NoContinuousStates#
Bases:
KModelContinuousStatesClass indicating there are no model continuous states.
- Karana.Models.P#
- Karana.Models.Sc#
- Karana.Models.S#
- Karana.Models.C#
- class Karana.Models.KModel(name: str, mm: Karana.Dynamics.ModelManager)#
Bases:
Generic[P,Sc,S,C],PyKModelBaseBase class for all Python models.
This is the base class for all Python models. To create a new model, simply create a class that derives from this one.
If the model has parameters, then create a parameter class that derives from KModelParams. In addition, add
` params: MyDerivedParamClass `as a class variable to ensure type-hinting works as intended.
Users can override the pre/postDeriv, pre/postHop, and pre/PostModelStep to run model functions at various points throughout the dynamics. For details on these methods and models, see the model documentation.
- params: P#
- scratch: Sc#
- discrete_states: S#
- continuous_states: C#
- typeString() str[source]#
Return the type string (class name) of the KModel.
- Returns:
The class name of the KModel.
- Return type:
str
- dumpString(prefix: str = '', options: Karana.Core.DumpOptionsBase | None = None) str[source]#
Return information about the KModel as a string.
- Parameters:
prefix (str) – A string to use as prefix for each output line.
options (_DumpOptionsBase | None) – Class with options to tailor the output
- Returns:
Information about the KModel as a string.
- Return type:
str
- class Karana.Models.BaseKModel#
Bases:
Karana.Core.LockingBaseThis BaseKModel serves as the base for all models. It implements common logic, methods, etc. for both C++ and Python models. Determining which methods have been overloaded is handled by the KModel classes. In C++ this is uses the curiously-recurring template pattern (CRTP) and in Python we use object attributes. See the KModel component models section for more discussion about the KModel class.
- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- stdDebugMsg(msg: str) None#
Print a standard debug message.
This creates json with debug information and passes it to the debug logger.
- Parameters:
msg – The message to log.
- class Karana.Models.CppKModelContinuousStates#
Bases:
Karana.Core.BaseA base class for continuous model states. Derive from this and add any continuous states for your model.
Override the isReady method to check whether the continuous states are set. Override the setX and getX to set and get the model continuous states. Whenever the number of continuous states changes (the length of the vector from getX changes), you MUST re-register the model. Neglecting to do so leads to undefined behavior. See the Continuous states section for more discussion about the KModel class.
- getX() Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]#
Get the continuous model states.
- Returns:
The continuous model states.
- getdX() Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]#
Get the derivative of the continuous model states.
- Returns:
The continuous model states’ derivatives.
- setX(x: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]) None#
Set the continuous model states.
- Parameters:
x – The new continuous model states.
- class Karana.Models.CppKModelDiscreteStates(name: str)#
Bases:
Karana.Core.BaseA base class for discrete model states. Derive from this and add any parameters for your model. Override the isReady method to check whether the discrete states are set. See the Discrete states section for more discussion about the KModel class.
- class Karana.Models.CppKModelScratch(name: str)#
Bases:
Karana.Core.Base
- class Karana.Models.KModelContinuousStates(name: str)#
Bases:
CppKModelContinuousStatesA base class for continuous model states. Derive from this and add any continuous states for your model.
Override the isReady method to check whether the continuous states are set. Override the setX and getX to set and get the model continuous states. Whenever the number of continuous states changes (the length of the vector from getX changes), you MUST re-register the model. Neglecting to do so leads to undefined behavior. See the Continuous states section for more discussion about the KModel class.
- class Karana.Models.KModelDiscreteStates(name: str)#
Bases:
CppKModelDiscreteStatesA base class for discrete model states. Derive from this and add any parameters for your model. Override the isReady method to check whether the discrete states are set. See the Discrete states section for more discussion about the KModel class.
- class Karana.Models.KModelScratch(name: str)#
Bases:
CppKModelScratchA scratchpad to store model information. This is primarily used for debugging purposes. See the Model scratch section for more discussion about the KModel class.
- class Karana.Models.OutputUpdateType(value: SupportsInt)#
Members:
PRE_HOP
PRE_DERIV
POST_DERIV
POST_HOP
- POST_DERIV: ClassVar[OutputUpdateType]#
- POST_HOP: ClassVar[OutputUpdateType]#
- PRE_DERIV: ClassVar[OutputUpdateType]#
- PRE_HOP: ClassVar[OutputUpdateType]#
- __members__: ClassVar[dict[str, OutputUpdateType]]#
- __eq__(other: Any) bool#
- __getstate__() int#
- __hash__() int#
- __index__() int#
- __int__() int#
- __ne__(other: Any) bool#
- __repr__() str#
- __setstate__(state: SupportsInt) None#
- __str__() str#
- property name: str#
- property value: int#
- class Karana.Models.PyKModelBase(name: str, mm: Karana.Dynamics.ModelManager)#
Bases:
BaseKModelKModel<T,P,Sc,S,C> uses the curiously recurring template pattern (CRTP) to determine what
methods the derived class has, and make the appropriate calls. All C++ models should derive from this. Python models will have a different class to derive from. See the KModel component models section for more discussion about the KModel class.
- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- dumpString(prefix: str, options: Karana.Core.DumpOptionsBase = None) str#
Return a string with the current model information.
- Parameters:
prefix (str) – The prefix to use in front of each line in the dump string.
options (BaseDumpOptions) – The options used to create the dump string.
- Returns:
A string representing the current model information.
- Return type:
str
- getPeriod() numpy.timedelta64#
If a nextModelStepTime method exists, then this returns a warning. A model period and nextModelStepTime cannot both be defined for a model. :returns: The model’s period.
- nextModelStepTime(t: float | numpy.timedelta64) numpy.timedelta64 | None#
- The model_period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the pre/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, the pre/postModelStep methods will run at the specified period.
The period is 0 and a nextModelStepTime method is defined. In this case, the nextModelStepTime defines when these methods will run.
- Parameters:
t (KTime) – The current time.
- Returns:
The next time this model should run.
- Return type:
KTime
- postDeriv(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
The postDeriv method runs after the multibody derivative.
- postHop(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
The postHop runs after each simulation hop.
- postModelStep(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
The postModelStep runs after the model’s step. See nextModelStepTime for information on when this happens.
- preDeriv(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
The preDeriv method runs before the multibody derivative.
- preHop(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
The preHop runs before each simulation hop.
- preModelStep(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
The preModelStep runs before the model’s step. See nextModelStepTime for information on when this happens.
- setPeriod(arg0: float | numpy.timedelta64) None#
The model_period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the
begin/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, the begin/postModelStep methods will run
- at the specified period.
The period is 0 and a nextModelStepTime method is defined. In this case, the
nextModelStepTime defines when these methods will run. A model period and nextModelStepTime cannot both be defined for a model. If one tries to set a model period for a model which has a nextModelStepTime, then an error will be thrown. :param t:
The new model period.
- class Karana.Models.ComputedTorque(name: str, mm: Karana.Dynamics.ModelManager, st: Karana.Dynamics.SubTree, set_accels_fn: collections.abc.Callable[[float | numpy.timedelta64, Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]], None])#
Bases:
ComputedTorqueKModelLimits the generalized force that can be applied to a subhinge.
- static create(name: str, mm: Karana.Dynamics.ModelManager, st: Karana.Dynamics.SubTree, set_accels_fn: collections.abc.Callable[[float | numpy.timedelta64, Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]], None]) ComputedTorque#
Constructor.
The user-supplied set_accels_fn should set the accelerations on the provided SubGraph. Then, the model uses Algorithms.evalComputedTorque to calculate the corresponding torques and apply them to the SubTree.
- Parameters:
name – The name of the model.
mm – The ModelManager to register this model with.
st – The SubTree to apply the torques to.
set_accels_fn – The function that sets the accelerations for the computed torque to compute torques for.
- Returns:
A ks_ptr to the newly created instance of the ComputedTorque model.
- preDeriv(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Calculate and apply the torques.
- Parameters:
t – Current time. This is passed to the user-supplied set_accels_fn.
x – Current state. This is passed to the user-supplied set_accels_fn.
- class Karana.Models.ComputedTorqueKModel#
Bases:
Karana.Models.BaseKModel- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- getNextModelStepTime(t: float | numpy.timedelta64) numpy.timedelta64 | None#
Get the next step time assuming the provided time t is a time the model has a step at.
- Parameters:
t (Ktime) – A time the model has a step at.
- Returns:
The next model step time.
- Return type:
Ktime
- getPeriod() numpy.timedelta64#
Get the period of the model.
If a nextModelStepTime method exists, this returns a warning. A model period and nextModelStepTime cannot both be defined for a model.
- Returns:
The model’s period.
- Return type:
Ktime
- isReady() bool#
Checks whether the model is ready.
- Returns:
Returns false if the params pointer is empty or if the parameters are not finalize. Returns true otherwise.
- Return type:
bool
- setPeriod(t: float | numpy.timedelta64) None#
Set the model period.
The model period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the preModelStep/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, those methods will run at the specified period.
The period is 0 and a nextModelStepTime method is defined. Then, that method defines when the steps will run.
A model period and nextModelStepTime cannot both be defined for a model. An error will be thrown if a model with nextModelStepTime has its period set.
- Parameters:
t (Ktime) – The new model period.
- class Karana.Models.DataLogger(name: str, mm: Karana.Dynamics.ModelManager, h5_writer: Karana.KUtils.H5Writer)#
Bases:
DataLoggerKModelThe DataLogger model updates the visualization at each postHop.
- static create(name: str, mm: Karana.Dynamics.ModelManager, h5_writer: Karana.KUtils.H5Writer) DataLogger#
Constructor.
- Parameters:
name – The name of the DataLogger model.
mm – The ModelManager to register this model with.
h5_writer – The H5Writer to use for logging.
- Returns:
A ks_ptr to the newly created instance of the DataLogger model.
- getH5Writer() Karana.KUtils.H5Writer#
Get the H5Writer used by the model.
This can be used to enable/disable various tables of the H5Writer.
- Returns:
The H5Write that this model uses for logging.
- postModelStep(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Perform data logging.
- Parameters:
t – Current time. Not used.
x – Current state. Not used.
- class Karana.Models.DataLoggerKModel#
Bases:
Karana.Models.BaseKModel- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- params: DataLoggerParams#
- getNextModelStepTime(t: float | numpy.timedelta64) numpy.timedelta64 | None#
Get the next step time assuming the provided time t is a time the model has a step at.
- Parameters:
t (Ktime) – A time the model has a step at.
- Returns:
The next model step time.
- Return type:
Ktime
- getPeriod() numpy.timedelta64#
Get the period of the model.
If a nextModelStepTime method exists, this returns a warning. A model period and nextModelStepTime cannot both be defined for a model.
- Returns:
The model’s period.
- Return type:
Ktime
- isReady() bool#
Checks whether the model is ready.
- Returns:
Returns false if the params pointer is empty or if the parameters are not finalize. Returns true otherwise.
- Return type:
bool
- setPeriod(t: float | numpy.timedelta64) None#
Set the model period.
The model period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the preModelStep/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, those methods will run at the specified period.
The period is 0 and a nextModelStepTime method is defined. Then, that method defines when the steps will run.
A model period and nextModelStepTime cannot both be defined for a model. An error will be thrown if a model with nextModelStepTime has its period set.
- Parameters:
t (Ktime) – The new model period.
- class Karana.Models.DataLoggerParams#
Parameters for the DataLogger model.
- isReady() bool#
Used to ensure the params are ready.
- Returns:
true if the params are ready, `false otherwise.
- property log_first_step: bool#
If true, then log the first step.
- class Karana.Models.DataPlotter(name: str, mm: Karana.Dynamics.ModelManager, plot_data: Karana.KUtils.PlotData)#
Bases:
DataPlotterKModelThe DataPlotter model updates the visualization at each postHop.
- static create(name: str, mm: Karana.Dynamics.ModelManager, plot_data: Karana.KUtils.PlotData) DataPlotter#
Constructor.
- Parameters:
name – The name of the DataPlotter model.
mm – The ModelManager to register this model with.
plot_data – The PlotData to use for updating plots.
- Returns:
A ks_ptr to the newly created instance of the DataPlotter model.
- getPlotData() Karana.KUtils.PlotData#
Get the H5Writer used by the model.
This can be used to enable/disable various tables of the H5Writer.
- Returns:
The H5Write that this model uses for logging.
- postModelStep(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Perform data logging.
- Parameters:
t – Current time. Not used.
x – Current state. Not used.
- class Karana.Models.DataPlotterKModel#
Bases:
Karana.Models.BaseKModel- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- params: DataPlotterParams#
- getNextModelStepTime(t: float | numpy.timedelta64) numpy.timedelta64 | None#
Get the next step time assuming the provided time t is a time the model has a step at.
- Parameters:
t (Ktime) – A time the model has a step at.
- Returns:
The next model step time.
- Return type:
Ktime
- getPeriod() numpy.timedelta64#
Get the period of the model.
If a nextModelStepTime method exists, this returns a warning. A model period and nextModelStepTime cannot both be defined for a model.
- Returns:
The model’s period.
- Return type:
Ktime
- isReady() bool#
Checks whether the model is ready.
- Returns:
Returns false if the params pointer is empty or if the parameters are not finalize. Returns true otherwise.
- Return type:
bool
- setPeriod(t: float | numpy.timedelta64) None#
Set the model period.
The model period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the preModelStep/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, those methods will run at the specified period.
The period is 0 and a nextModelStepTime method is defined. Then, that method defines when the steps will run.
A model period and nextModelStepTime cannot both be defined for a model. An error will be thrown if a model with nextModelStepTime has its period set.
- Parameters:
t (Ktime) – The new model period.
- class Karana.Models.DataPlotterParams#
Parameters for the DataPlotter model.
- isReady() bool#
Used to ensure the params are ready.
- Returns:
true if the params are ready, `false otherwise.
- property log_first_step: bool#
If true, then log the first step.
- class Karana.Models.GraphicalSceneMovie(name: str, mm: Karana.Dynamics.ModelManager, scene: Karana.Scene.ProxyScene)#
Bases:
GraphicalSceneMovieKModelThe GraphicalSceneMovie model updates the visualization at each postHop.
- static create(name: str, mm: Karana.Dynamics.ModelManager, scene: Karana.Scene.ProxyScene) GraphicalSceneMovie#
Constructor.
- Parameters:
name – The name of the GraphicalSceneMovie model.
mm – The ModelManager to register this model with.
scene – The ProxyScene whose graphics() scene’s frames will be rendered to create a movie.
- Returns:
A ks_ptr to the newly created instance of the GraphicalSceneMovie model.
- getFfmpegCommand() str#
Get the ffmpeg command you should run to turn the images into a movie.
- Returns:
The ffmpeg command you should run to turn the images into a movie as a string.
- postModelStep(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Update the GraphicalScene.
- Parameters:
t – Current time. Not used.
x – Current state. Not used.
- class Karana.Models.GraphicalSceneMovieKModel#
Bases:
Karana.Models.BaseKModel- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- params: GraphicalSceneMovieParams#
- getNextModelStepTime(t: float | numpy.timedelta64) numpy.timedelta64 | None#
Get the next step time assuming the provided time t is a time the model has a step at.
- Parameters:
t (Ktime) – A time the model has a step at.
- Returns:
The next model step time.
- Return type:
Ktime
- getPeriod() numpy.timedelta64#
Get the period of the model.
If a nextModelStepTime method exists, this returns a warning. A model period and nextModelStepTime cannot both be defined for a model.
- Returns:
The model’s period.
- Return type:
Ktime
- isReady() bool#
Checks whether the model is ready.
- Returns:
Returns false if the params pointer is empty or if the parameters are not finalize. Returns true otherwise.
- Return type:
bool
- setPeriod(t: float | numpy.timedelta64) None#
Set the model period.
The model period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the preModelStep/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, those methods will run at the specified period.
The period is 0 and a nextModelStepTime method is defined. Then, that method defines when the steps will run.
A model period and nextModelStepTime cannot both be defined for a model. An error will be thrown if a model with nextModelStepTime has its period set.
- Parameters:
t (Ktime) – The new model period.
- class Karana.Models.GraphicalSceneMovieParams#
Parameters for the GraphicalSceneMovie model.
- isReady() bool#
Used to ensure the params are ready.
- Returns:
true if the params are ready, `false otherwise.
- property dir: str#
Directory where the renders will be saved.
- property filename_prefix: str#
Filename prefix for each individual file
- class Karana.Models.Gravity(name: str, mm: Karana.Dynamics.ModelManager, gravity_interface: GravityInterface, st: Karana.Dynamics.SubTree)#
Bases:
GravityKModelApply uniform gravitational acceleration to each body in the provided multibody.
- static create(name: str, mm: Karana.Dynamics.ModelManager, gravity_interface: GravityInterface, st: Karana.Dynamics.SubTree) Gravity#
Constructor.
- Parameters:
name – The name of the model.
mm – The ModelManager to register this model with.
gravity_interface – The GravityInterface used to compute gravity.
st – The SubTree to apply uniform gravity to.
- Returns:
A ks_ptr to the newly created instance of the Gravity model.
- getGravityInterface() GravityInterface#
Get the gravity interface used by this KModel.
- Returns:
The gravity interface used by this KModel.
- preDeriv(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Calculate and apply the aerodynamic force.
- Parameters:
t – Current time.
x – Current state. Not used.
- class Karana.Models.GravityInterface#
Bases:
Karana.Core.BaseCommon GravityInterface used for computing gravity with various methods.
- getGravity() GravityOutput#
Get the GravityOutput data.
- Returns:
The GravityOutput data.
- isReady() bool#
Used to ensure the params are ready.
- Returns:
true if the params are ready, `false otherwise.
- setGravity(g: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]], t: float | numpy.timedelta64, output_update_type: Karana.Models.OutputUpdateType) None#
Set the GravityOutput data.
- Parameters:
g – The acceleration due to gravity.
t – The time this acceleration was calculated at.
output_update_type – The type of update that updated the gravity.
- class Karana.Models.GravityKModel#
Bases:
Karana.Models.BaseKModel- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- getNextModelStepTime(t: float | numpy.timedelta64) numpy.timedelta64 | None#
Get the next step time assuming the provided time t is a time the model has a step at.
- Parameters:
t (Ktime) – A time the model has a step at.
- Returns:
The next model step time.
- Return type:
Ktime
- getPeriod() numpy.timedelta64#
Get the period of the model.
If a nextModelStepTime method exists, this returns a warning. A model period and nextModelStepTime cannot both be defined for a model.
- Returns:
The model’s period.
- Return type:
Ktime
- isReady() bool#
Checks whether the model is ready.
- Returns:
Returns false if the params pointer is empty or if the parameters are not finalize. Returns true otherwise.
- Return type:
bool
- setPeriod(t: float | numpy.timedelta64) None#
Set the model period.
The model period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the preModelStep/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, those methods will run at the specified period.
The period is 0 and a nextModelStepTime method is defined. Then, that method defines when the steps will run.
A model period and nextModelStepTime cannot both be defined for a model. An error will be thrown if a model with nextModelStepTime has its period set.
- Parameters:
t (Ktime) – The new model period.
- toDS() Karana.Models.GeneralKModels_types.GravityDS#
Create a GravityDS from this Gravity model.
- Returns:
GravityDS
A GravityDS instance with values set to match this model.
- class Karana.Models.GravityOutput#
The output of a GravityInterface.
- update_type: Karana.Models.OutputUpdateType#
- property g: Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#
- property t: numpy.timedelta64#
- class Karana.Models.PID(name: str, mm: Karana.Dynamics.ModelManager, sh: Karana.Dynamics.PhysicalSubhinge, q_traj: collections.abc.Callable[[float | numpy.timedelta64], Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]], u_traj: collections.abc.Callable[[float | numpy.timedelta64], Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]])#
Bases:
PIDKModelSimple PID controller model.
- static create(name: str, mm: Karana.Dynamics.ModelManager, sh: Karana.Dynamics.PhysicalSubhinge, q_traj: collections.abc.Callable[[float | numpy.timedelta64], Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]], u_traj: collections.abc.Callable[[float | numpy.timedelta64], Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]]) PID#
- Constructor. The PID model adds force to a subhinge. The model uses
the incoming function as the desired trajectory. The output of this function should be the desired Q values of the subhinge.
- Parameters:
name – The name of the model.
mm – The ModelManager to register this model with.
sh – The Subhinge to apply the forces calculated by the PID controller to.
q_traj – A function that defines the reference trajectory for Q.
u_traj – A function that defines the reference trajectory for U.
- Returns:
A ks_ptr to the newly created instance of the PID model.
- preDeriv(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Calculate and apply the output of the PID model to the subhinge. :param t: Current time. :param x: Current state. Not used.
- preModelStep(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Calculate the contribution of integral control. :param t: Current time. :param x: Current state. Not used.
- class Karana.Models.PIDKModel#
Bases:
Karana.Models.BaseKModel- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- getNextModelStepTime(t: float | numpy.timedelta64) numpy.timedelta64 | None#
Get the next step time assuming the provided time t is a time the model has a step at.
- Parameters:
t (Ktime) – A time the model has a step at.
- Returns:
The next model step time.
- Return type:
Ktime
- getPeriod() numpy.timedelta64#
Get the period of the model.
If a nextModelStepTime method exists, this returns a warning. A model period and nextModelStepTime cannot both be defined for a model.
- Returns:
The model’s period.
- Return type:
Ktime
- isReady() bool#
Checks whether the model is ready.
- Returns:
Returns false if the params pointer is empty or if the parameters are not finalize. Returns true otherwise.
- Return type:
bool
- setPeriod(t: float | numpy.timedelta64) None#
Set the model period.
The model period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the preModelStep/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, those methods will run at the specified period.
The period is 0 and a nextModelStepTime method is defined. Then, that method defines when the steps will run.
A model period and nextModelStepTime cannot both be defined for a model. An error will be thrown if a model with nextModelStepTime has its period set.
- Parameters:
t (Ktime) – The new model period.
- class Karana.Models.PIDParams#
Parameters for the PID model.
- isReady() bool#
Used to ensure the params are ready.
- Returns:
true if the params are ready, `false otherwise.
- property kd: float#
Derivative gain
- property ki: float#
Integral gain
- property kp: float#
Proportional gain
- class Karana.Models.PinJointLimits(name: str, mm: Karana.Dynamics.ModelManager, pin: Karana.Dynamics.PinSubhinge)#
Bases:
PinJointLimitsKModelModel that adds joint limits to a pin hinge.
- static create(name: str, mm: Karana.Dynamics.ModelManager, pin: Karana.Dynamics.PinSubhinge) PinJointLimits#
Constructor.
- Parameters:
name – The name of the model.
mm – The ModelManager to register this model with.
pin – The pin subhinge to apply joint limits to.
- Returns:
A ks_ptr to the newly created instance of the PinJointLimits model.
- preDeriv(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Calculate and apply the restoring force to mimic joint limits. :param t:
Current time. Not used.
- Parameters:
x –
Current state. Not used.
- class Karana.Models.PinJointLimitsKModel#
Bases:
Karana.Models.BaseKModel- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- params: PinJointLimitsParams#
- getNextModelStepTime(t: float | numpy.timedelta64) numpy.timedelta64 | None#
Get the next step time assuming the provided time t is a time the model has a step at.
- Parameters:
t (Ktime) – A time the model has a step at.
- Returns:
The next model step time.
- Return type:
Ktime
- getPeriod() numpy.timedelta64#
Get the period of the model.
If a nextModelStepTime method exists, this returns a warning. A model period and nextModelStepTime cannot both be defined for a model.
- Returns:
The model’s period.
- Return type:
Ktime
- isReady() bool#
Checks whether the model is ready.
- Returns:
Returns false if the params pointer is empty or if the parameters are not finalize. Returns true otherwise.
- Return type:
bool
- setPeriod(t: float | numpy.timedelta64) None#
Set the model period.
The model period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the preModelStep/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, those methods will run at the specified period.
The period is 0 and a nextModelStepTime method is defined. Then, that method defines when the steps will run.
A model period and nextModelStepTime cannot both be defined for a model. An error will be thrown if a model with nextModelStepTime has its period set.
- Parameters:
t (Ktime) – The new model period.
- class Karana.Models.PinJointLimitsParams#
Parameters for the PinJointLimits model.
- isReady() bool#
Used to ensure the params are ready.
- Returns:
true if the params are ready, `false otherwise.
- property d: float#
Damping constant for the restoring force
- property k: float#
Spring constant for the restoring force
- property lower_limit: float#
Pin joint lower limit
- property upper_limit: float#
Pin joint upper limit
- class Karana.Models.PointMassGravity(name: str, st: Karana.Dynamics.SubTree, central_body: Karana.Frame.Frame)#
Bases:
GravityInterfaceA GravityInterface implementation for point-mass gravity.
- static create(name: str, st: Karana.Dynamics.SubTree, central_body: Karana.Frame.Frame) PointMassGravity#
Constructor.
- Parameters:
name – The name of the PointMassGravity interface.
st – The SubTree to get the center of mass from.
central_body – The point mass central body applying the gravitational force
- Returns:
A pointer to the newly created instance of PointMassGravity.
- getObjIds() Annotated[list[int], FixedSize(2)]#
- Get the IDs of the SubTree and central body used
by this PointMassGravity.
- Returns:
The IDs of the SubTree and central body used by this PointMassGravity.
- toDS() Karana.Models.GeneralKModels_types.PointMassGravityDS#
Create a PointMassGravityDS from this PointMassGravity model.
- Returns:
PointMassGravityDS
A PointMassGravityDS instance with values set to match this model.
- property mu: float#
m^3/(kg s^2) )
- Type:
Gravitational constant (units
- class Karana.Models.ProjectConstraintError(name: str, mm: Karana.Dynamics.ModelManager, sg: Karana.Dynamics.SubGraph, integrator: Karana.Math.Integrator, cks: Karana.Dynamics.ConstraintKinematicsSolver)#
Bases:
ProjectConstraintErrorKModelThe ProjectConstraintError model updates the visualization at each postHop.
- static create(name: str, mm: Karana.Dynamics.ModelManager, sg: Karana.Dynamics.SubGraph, integrator: Karana.Math.Integrator, cks: Karana.Dynamics.ConstraintKinematicsSolver) ProjectConstraintError#
Constructor.
- Parameters:
name – The name of the ProjectConstraintError model.
mm – The ModelManager to register this model with.
sg – The SubGraph whose coordinates will be projected.
cks – The ConstraintKinematicsSolver used to do the projection.
integrator – The integrator to soft-reset when doing a projection.
- Returns:
A ks_ptr to the newly created instance of the ProjectConstraintError model.
- postModelStep(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Project the coordinates to satisfy the constraints if the current error is larger
than the tolerance.
- Parameters:
t – Current time. Unused.
x – Current state. Unused.
- class Karana.Models.ProjectConstraintErrorKModel#
Bases:
Karana.Models.BaseKModel- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- params: ProjectConstraintErrorParams#
- getNextModelStepTime(t: float | numpy.timedelta64) numpy.timedelta64 | None#
Get the next step time assuming the provided time t is a time the model has a step at.
- Parameters:
t (Ktime) – A time the model has a step at.
- Returns:
The next model step time.
- Return type:
Ktime
- getPeriod() numpy.timedelta64#
Get the period of the model.
If a nextModelStepTime method exists, this returns a warning. A model period and nextModelStepTime cannot both be defined for a model.
- Returns:
The model’s period.
- Return type:
Ktime
- isReady() bool#
Checks whether the model is ready.
- Returns:
Returns false if the params pointer is empty or if the parameters are not finalize. Returns true otherwise.
- Return type:
bool
- setPeriod(t: float | numpy.timedelta64) None#
Set the model period.
The model period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the preModelStep/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, those methods will run at the specified period.
The period is 0 and a nextModelStepTime method is defined. Then, that method defines when the steps will run.
A model period and nextModelStepTime cannot both be defined for a model. An error will be thrown if a model with nextModelStepTime has its period set.
- Parameters:
t (Ktime) – The new model period.
- class Karana.Models.ProjectConstraintErrorParams#
Parameters for the ProjectConstraintError model.
- isReady() bool#
Used to ensure the params are ready.
- Returns:
true if the params are ready, `false otherwise.
- property tol: float#
Directory where the renders will be saved.
- class Karana.Models.SpringDamper(name: str, mm: Karana.Dynamics.ModelManager, nd1: Karana.Dynamics.Node, nd2: Karana.Dynamics.Node)#
Bases:
SpringDamperKModelAdds a spring-damper between two nodes.
- static create(name: str, mm: Karana.Dynamics.ModelManager, nd1: Karana.Dynamics.Node, nd2: Karana.Dynamics.Node) SpringDamper#
Constructor. The SpringDamper model applies an equal and opposing force to two nodes based on their current distance apart.
- Parameters:
name – The name of the model.
mm – The ModelManager to register this model with.
nd1 – The first node in the spring damper model.
nd2 – The second node in the spring damper model.
- Returns:
A ks_ptr to the newly created instance of the SpringDamper model.
- getNodeIds() list[int]#
Get node IDs for DataStruct.
This method retrieves the IDs of the two nodes. This is designed primarily for use with the SpringDamperDS DataStruct.
- Returns:
Nodes’ IDs.
- preDeriv(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Calculate and apply the spring/damper force. :param t: Current time. Not used. :param x: Current state. Not used.
- sourceNode() Karana.Dynamics.Node#
Get the first node of the spring-damper
- Returns:
The node
- targetNode() Karana.Dynamics.Node#
Get the second node of the spring-damper
- Returns:
The node
- toDS() Karana.Models.GeneralKModels_types.SpringDamperDS#
Create a SpringDamperDS from this SpringDamper model.
- Returns:
SpringDamperDS
A SpringDamperDS instance with values set to match this model.
- class Karana.Models.SpringDamperKModel#
Bases:
Karana.Models.BaseKModel- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- params: SpringDamperParams#
- scratch: SpringDamperScratch#
- getNextModelStepTime(t: float | numpy.timedelta64) numpy.timedelta64 | None#
Get the next step time assuming the provided time t is a time the model has a step at.
- Parameters:
t (Ktime) – A time the model has a step at.
- Returns:
The next model step time.
- Return type:
Ktime
- getPeriod() numpy.timedelta64#
Get the period of the model.
If a nextModelStepTime method exists, this returns a warning. A model period and nextModelStepTime cannot both be defined for a model.
- Returns:
The model’s period.
- Return type:
Ktime
- isReady() bool#
Checks whether the model is ready.
- Returns:
Returns false if the params pointer is empty or if the parameters are not finalize. Returns true otherwise.
- Return type:
bool
- setPeriod(t: float | numpy.timedelta64) None#
Set the model period.
The model period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the preModelStep/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, those methods will run at the specified period.
The period is 0 and a nextModelStepTime method is defined. Then, that method defines when the steps will run.
A model period and nextModelStepTime cannot both be defined for a model. An error will be thrown if a model with nextModelStepTime has its period set.
- Parameters:
t (Ktime) – The new model period.
- class Karana.Models.SpringDamperParams#
Parameters for the SpringDamper model.
- isReady() bool#
Used to ensure the params are ready.
- Returns:
true if the params are ready, `false otherwise.
- property d: float#
Damper constant
- property k: float#
Spring constant
- property unsprung_length: float#
Unsprung length
- class Karana.Models.SpringDamperScratch#
Scratch variables for the SpringDamper model.
- property damping_force: Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#
Linear force due to spring damping
- property offset: Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#
Translation from node1 to node2
- property position_error: float#
Signed length offset from the unsprung length
- property stiffness_force: float#
Signed scalar force due to spring stiffness
- property total_force: Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#
Total linear spring force
- property velocity_error: Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#
Relative linear velocity across the spring
- class Karana.Models.SubhingeForceLimits(name: str, mm: Karana.Dynamics.ModelManager, sh: Karana.Dynamics.PhysicalSubhinge)#
Bases:
SubhingeForceLimitsKModelLimits the generalized force that can be applied to a subhinge.
- static create(name: str, mm: Karana.Dynamics.ModelManager, sh: Karana.Dynamics.PhysicalSubhinge) SubhingeForceLimits#
Constructor. The SubhingeForceLimits models actuator saturation limits for a subhinge. This clamps the generalized force of the subhinge using a lower bound and upper bound defined by lower_limits and upper_limits in the param.
- Parameters:
name – The name of the model.
mm – The ModelManager to register this model with.
sh – The subhinge to add the force limits to.
- Returns:
A ks_ptr to the newly created instance of the SubhingeForceLimits model.
- preDeriv(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Calculate and apply the spring/damper force.
- Parameters:
t – Current time. Not used.
x – Current state. Not used.
- class Karana.Models.SubhingeForceLimitsKModel#
Bases:
Karana.Models.BaseKModel- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- params: SubhingeForceLimitsParams#
- getNextModelStepTime(t: float | numpy.timedelta64) numpy.timedelta64 | None#
Get the next step time assuming the provided time t is a time the model has a step at.
- Parameters:
t (Ktime) – A time the model has a step at.
- Returns:
The next model step time.
- Return type:
Ktime
- getPeriod() numpy.timedelta64#
Get the period of the model.
If a nextModelStepTime method exists, this returns a warning. A model period and nextModelStepTime cannot both be defined for a model.
- Returns:
The model’s period.
- Return type:
Ktime
- isReady() bool#
Checks whether the model is ready.
- Returns:
Returns false if the params pointer is empty or if the parameters are not finalize. Returns true otherwise.
- Return type:
bool
- setPeriod(t: float | numpy.timedelta64) None#
Set the model period.
The model period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the preModelStep/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, those methods will run at the specified period.
The period is 0 and a nextModelStepTime method is defined. Then, that method defines when the steps will run.
A model period and nextModelStepTime cannot both be defined for a model. An error will be thrown if a model with nextModelStepTime has its period set.
- Parameters:
t (Ktime) – The new model period.
- class Karana.Models.SubhingeForceLimitsParams#
Parameters for the SubhingeForceLimits model.
- isReady() bool#
Used to ensure the params are ready.
- Returns:
true if the params are ready, `false otherwise.
- property lower_limits: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]#
Lower bound for the force limit
- property upper_limits: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]#
Upper bound for the force limit
- class Karana.Models.SubhingeSpringDamper(name: str, mm: Karana.Dynamics.ModelManager, sh: Karana.Dynamics.PhysicalSubhinge)#
Bases:
SubhingeSpringDamperKModelAdds a spring damper to the provided subhinge.
- static create(name: str, mm: Karana.Dynamics.ModelManager, sh: Karana.Dynamics.PhysicalSubhinge) SubhingeSpringDamper#
Constructor. The SubhingeSpringDamper model a spring damper force to a subhinge
based on a given setpoint.
- Parameters:
name – The name of the model.
mm – The ModelManager to register this model with.
sh – The subhinge to add the spring damper to.
- Returns:
A ks_ptr to the newly created instance of the SubhingeSpringDamper model.
- preDeriv(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Calculate and apply the spring/damper force.
- Parameters:
t – Current time. Not used.
x – Current state. Not used.
- class Karana.Models.SubhingeSpringDamperKModel#
Bases:
Karana.Models.BaseKModel- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- params: SubhingeSpringDamperParams#
- getNextModelStepTime(t: float | numpy.timedelta64) numpy.timedelta64 | None#
Get the next step time assuming the provided time t is a time the model has a step at.
- Parameters:
t (Ktime) – A time the model has a step at.
- Returns:
The next model step time.
- Return type:
Ktime
- getPeriod() numpy.timedelta64#
Get the period of the model.
If a nextModelStepTime method exists, this returns a warning. A model period and nextModelStepTime cannot both be defined for a model.
- Returns:
The model’s period.
- Return type:
Ktime
- isReady() bool#
Checks whether the model is ready.
- Returns:
Returns false if the params pointer is empty or if the parameters are not finalize. Returns true otherwise.
- Return type:
bool
- setPeriod(t: float | numpy.timedelta64) None#
Set the model period.
The model period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the preModelStep/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, those methods will run at the specified period.
The period is 0 and a nextModelStepTime method is defined. Then, that method defines when the steps will run.
A model period and nextModelStepTime cannot both be defined for a model. An error will be thrown if a model with nextModelStepTime has its period set.
- Parameters:
t (Ktime) – The new model period.
- class Karana.Models.SubhingeSpringDamperParams#
Parameters for the SubhingeSpringDamper model.
- isReady() bool#
Used to ensure the params are ready.
- Returns:
true if the params are ready, `false otherwise.
- property d: float#
Damper constant
- property k: float#
Spring constant
- property setpoint: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]#
Setpoint for the subhinge
- class Karana.Models.SyncRealTime(name: str, mm: Karana.Dynamics.ModelManager, rt_speed: SupportsFloat = 1.0)#
Bases:
SyncRealTimeKModelLimits sim speed to a multiple of real time.
- static create(name: str, mm: Karana.Dynamics.ModelManager, rt_speed: SupportsFloat = 1.0) SyncRealTime#
Constructor.
- Parameters:
name – The name of the model.
mm – The ModelManager to register this model with.
rt_speed – The multiple of real time to limit to.
- Returns:
A ks_ptr to the newly created instance of the SyncRealTime model.
- postHop(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Sleep as needed to sync to real time.
- Parameters:
t – Current time.
x – Current state. Not used.
- preHop(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Record the start-hop time.
- Parameters:
t – Current time.
x – Current state. Not used.
- class Karana.Models.SyncRealTimeKModel#
Bases:
Karana.Models.BaseKModel- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- getNextModelStepTime(t: float | numpy.timedelta64) numpy.timedelta64 | None#
Get the next step time assuming the provided time t is a time the model has a step at.
- Parameters:
t (Ktime) – A time the model has a step at.
- Returns:
The next model step time.
- Return type:
Ktime
- getPeriod() numpy.timedelta64#
Get the period of the model.
If a nextModelStepTime method exists, this returns a warning. A model period and nextModelStepTime cannot both be defined for a model.
- Returns:
The model’s period.
- Return type:
Ktime
- isReady() bool#
Checks whether the model is ready.
- Returns:
Returns false if the params pointer is empty or if the parameters are not finalize. Returns true otherwise.
- Return type:
bool
- setPeriod(t: float | numpy.timedelta64) None#
Set the model period.
The model period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the preModelStep/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, those methods will run at the specified period.
The period is 0 and a nextModelStepTime method is defined. Then, that method defines when the steps will run.
A model period and nextModelStepTime cannot both be defined for a model. An error will be thrown if a model with nextModelStepTime has its period set.
- Parameters:
t (Ktime) – The new model period.
- class Karana.Models.TimeDisplay(name: str, mm: Karana.Dynamics.ModelManager, scene: Karana.Scene.GraphicalScene)#
Bases:
TimeDisplayKModelThe TimeDisplay model updates the visualization at each postHop.
- static create(name: str, mm: Karana.Dynamics.ModelManager, scene: Karana.Scene.GraphicalScene) TimeDisplay#
Constructor.
- Parameters:
name – The name of the model.
mm – The ModelManager to register this model with.
scene – The GraphicalScene to display the time in.
- Returns:
A ks_ptr to the newly created instance of the TimeDisplay model.
- postModelStep(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Update the time display
- Parameters:
t – Current time. Not used.
x – Current state. Not used.
- class Karana.Models.TimeDisplayKModel#
Bases:
Karana.Models.BaseKModel- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- params: TimeDisplayParams#
- getNextModelStepTime(t: float | numpy.timedelta64) numpy.timedelta64 | None#
Get the next step time assuming the provided time t is a time the model has a step at.
- Parameters:
t (Ktime) – A time the model has a step at.
- Returns:
The next model step time.
- Return type:
Ktime
- getPeriod() numpy.timedelta64#
Get the period of the model.
If a nextModelStepTime method exists, this returns a warning. A model period and nextModelStepTime cannot both be defined for a model.
- Returns:
The model’s period.
- Return type:
Ktime
- isReady() bool#
Checks whether the model is ready.
- Returns:
Returns false if the params pointer is empty or if the parameters are not finalize. Returns true otherwise.
- Return type:
bool
- setPeriod(t: float | numpy.timedelta64) None#
Set the model period.
The model period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the preModelStep/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, those methods will run at the specified period.
The period is 0 and a nextModelStepTime method is defined. Then, that method defines when the steps will run.
A model period and nextModelStepTime cannot both be defined for a model. An error will be thrown if a model with nextModelStepTime has its period set.
- Parameters:
t (Ktime) – The new model period.
- class Karana.Models.TimeDisplayParams#
Parameters for the TimeDisplay KModel.
- isReady() bool#
Used to ensure the params are ready.
- Returns:
true if the params are ready, false otherwise.
- property color: Karana.Scene.Color#
Color of the time text
- class Karana.Models.UniformGravity(name: str)#
Bases:
GravityInterfaceA GravityInterface implementation for uniform gravity.
- static create(name: str) UniformGravity#
Constructor.
- Parameters:
name – The name of the UniformGravity interface.
- Returns:
A pointer to the newly created instance of UniformGravity.
- toDS() Karana.Models.GeneralKModels_types.UniformGravityDS#
Create a UniformGravityDS from this UniformGravity model.
- Returns:
UniformGravityDS
A UniformGravityDS instance with values set to match this model.
- class Karana.Models.UpdateProxyScene(name: str, mm: Karana.Dynamics.ModelManager, scene: Karana.Scene.ProxyScene)#
Bases:
UpdateProxySceneKModelThe UpdateProxyScene model updates the visualization at each postHop.
- static create(name: str, mm: Karana.Dynamics.ModelManager, scene: Karana.Scene.ProxyScene) UpdateProxyScene#
Constructor.
- Parameters:
name – The name of the model.
mm – The ModelManager to register this model with.
scene – The ProxyScene to call update on.
- Returns:
A ks_ptr to the newly created instance of the UpdateProxyScene model.
- postHop(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Update the ProxyScene.
- Parameters:
t – Current time. Not used.
x – Current state. Not used.
- class Karana.Models.UpdateProxySceneKModel#
Bases:
Karana.Models.BaseKModel- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- getNextModelStepTime(t: float | numpy.timedelta64) numpy.timedelta64 | None#
Get the next step time assuming the provided time t is a time the model has a step at.
- Parameters:
t (Ktime) – A time the model has a step at.
- Returns:
The next model step time.
- Return type:
Ktime
- getPeriod() numpy.timedelta64#
Get the period of the model.
If a nextModelStepTime method exists, this returns a warning. A model period and nextModelStepTime cannot both be defined for a model.
- Returns:
The model’s period.
- Return type:
Ktime
- isReady() bool#
Checks whether the model is ready.
- Returns:
Returns false if the params pointer is empty or if the parameters are not finalize. Returns true otherwise.
- Return type:
bool
- setPeriod(t: float | numpy.timedelta64) None#
Set the model period.
The model period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the preModelStep/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, those methods will run at the specified period.
The period is 0 and a nextModelStepTime method is defined. Then, that method defines when the steps will run.
A model period and nextModelStepTime cannot both be defined for a model. An error will be thrown if a model with nextModelStepTime has its period set.
- Parameters:
t (Ktime) – The new model period.
- class Karana.Models.PenaltyContact(name: str, mm: Karana.Dynamics.ModelManager, st: Karana.Dynamics.SubTree, colliders: collections.abc.Sequence[Karana.Collision.FrameCollider], default_contact_force_model: Karana.Collision.ContactForceBase)#
Bases:
PenaltyContactKModelModel applying penalty contact forces to collisions from the provided FrameColliders.
This model takes the provided FrameCollider(s) and passes their colliding pairs to the provided ContactForceBase to calculate and apply contact forces.
See Collision dynamics for more discussion on contact and collision dynamics.
- static create(name: str, mm: Karana.Dynamics.ModelManager, st: Karana.Dynamics.SubTree, colliders: collections.abc.Sequence[Karana.Collision.FrameCollider], default_contact_force_model: Karana.Collision.ContactForceBase) PenaltyContact#
Create a PenaltyContact model.
- Parameters:
name –
The name of the model.
mm – The ModelManager to register this model with.
st –
The SubTree that this model is operating on.
colliders –
Helpers to generate body contacts.
contact_force_model –
The model used for computing contact
forces.
- Returns:
The created PenaltyContact model.
- getContactForceModel() Karana.Collision.ContactForceBase#
Return the registered contact force model.
- Returns:
The contact force model.
- preDeriv(name: float | numpy.timedelta64, collider: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#
Apply penalty contact forces.
- Parameters:
t –
Current time. Not used.
x –
Current state. Not used.
- class Karana.Models.PenaltyContactKModel#
Bases:
Karana.Models.BaseKModel- debug_model: bool#
- model_manager: Karana.Dynamics.ModelManager#
- getNextModelStepTime(t: float | numpy.timedelta64) numpy.timedelta64 | None#
Get the next step time assuming the provided time t is a time the model has a step at.
- Parameters:
t (Ktime) – A time the model has a step at.
- Returns:
The next model step time.
- Return type:
Ktime
- getPeriod() numpy.timedelta64#
Get the period of the model.
If a nextModelStepTime method exists, this returns a warning. A model period and nextModelStepTime cannot both be defined for a model.
- Returns:
The model’s period.
- Return type:
Ktime
- isReady() bool#
Checks whether the model is ready.
- Returns:
Returns false if the params pointer is empty or if the parameters are not finalize. Returns true otherwise.
- Return type:
bool
- setPeriod(t: float | numpy.timedelta64) None#
Set the model period.
The model period defines the period at which the model runs. There are a few cases to consider:
The period is 0 and no nextModelStepTime method is defined. In this case, the preModelStep/postModelStep methods will run every time a simulation hop happens.
The period is non-zero. In this case, those methods will run at the specified period.
The period is 0 and a nextModelStepTime method is defined. Then, that method defines when the steps will run.
A model period and nextModelStepTime cannot both be defined for a model. An error will be thrown if a model with nextModelStepTime has its period set.
- Parameters:
t (Ktime) – The new model period.