Karana.Models

Contents

Karana.Models#

General models used in a variety of simulations.

Submodules#

Attributes#

P

Sc

S

C

Classes#

KModelParams

BaseClass for the model parameters of Python models.

NoParams

Class indicating there are no model params.

NoScratch

Class indicating there is no model scratch.

NoDiscreteStates

Class indicating there are no model discrete states.

NoContinuousStates

Class indicating there are no model continuous states.

KModel

Base class for all Python models.

BaseKModel

This BaseKModel serves as the base for all models. It implements

CppKModelContinuousStates

A base class for continuous model states. Derive from this and add any

KModelContinuousStates

A base class for continuous model states. Derive from this and add any

KModelDiscreteStates

A base class for discrete model states. Derive from this and add any

KModelScratch

PyKModelBase

KModel<T,P,Sc,S,C> uses the curiously recurring template pattern

ComputedTorque

Limits the generalized force that can be applied to a subhinge.

ComputedTorqueKModel

DataLogger

The DataLogger model updates the visualization at each postHop.

DataLoggerKModel

DataLoggerParams

Parameters for the DataLogger model.

GraphicalSceneMovie

The GraphicalSceneMovie model updates the visualization at each

GraphicalSceneMovieKModel

GraphicalSceneMovieParams

Parameters for the GraphicalSceneMovie model.

PID

Simple PID controller model.

PIDKModel

PIDParams

Parameters for the PID model.

PinJointLimits

Model that adds joint limits to a pin hinge.

PinJointLimitsKModel

PinJointLimitsParams

Parameters for the PinJointLimits model.

PointMassGravity

Model to compute and apply uniform gravity accelearation from a point

PointMassGravityKModel

PointMassGravityParams

Parameters for the PointMassGravity model.

ProjectConstraintError

The ProjectConstraintError model updates the visualization at each

ProjectConstraintErrorKModel

ProjectConstraintErrorParams

Parameters for the ProjectConstraintError model.

SpringDamper

Adds a spring-damper between two nodes.

SpringDamperKModel

SpringDamperParams

Parameters for the SpringDamper model.

SubhingeForceLimits

Limits the generalized force that can be applied to a subhinge.

SubhingeForceLimitsKModel

SubhingeForceLimitsParams

Paramters for the SubhingeForceLimits model.

SubhingeSpringDamper

Adds a spring damper to the provided subhinge.

SubhingeSpringDamperKModel

SubhingeSpringDamperParams

Parameters for the SubhingeSpringDamper model.

SyncRealTime

Limits sim speed to a multiple of real time.

SyncRealTimeKModel

TimeDisplay

The TimeDisplay model updates the visualization at each postHop.

TimeDisplayKModel

TimeDisplayParams

UniformGravity

Apply uniform gravitational acceleration to each body in the provided

UniformGravityKModel

UniformGravityParams

Parameters for the UniformGravity class.

UpdateProxyScene

The UpdateProxyScene model updates the visualization at each postHop.

UpdateProxySceneKModel

DataPlotter

DataPlotter model.

PenaltyContact

Model applying penalty forces proportional to collision penetration

PenaltyContactKModel

Package Contents#

class Karana.Models.KModelParams(/, **data: Any)#

Bases: Karana.KUtils.DataStruct.DataStruct

BaseClass 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 isFinalized if applicable to ensure that all model parameters have been defined.

isFinalized() bool[source]#

Return true if all the parameters are finalized. False otherwise.

class Karana.Models.NoParams(/, **data: Any)#

Bases: KModelParams

Class indicating there are no model params.

class Karana.Models.NoScratch#

Bases: KModelScratch

Class indicating there is no model scratch.

class Karana.Models.NoDiscreteStates#

Bases: KModelDiscreteStates

Class indicating there are no model discrete states.

class Karana.Models.NoContinuousStates#

Bases: KModelContinuousStates

Class 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, sp: Karana.Dynamics.StatePropagator)#

Bases: Generic[P, Sc, S, C], PyKModelBase

Base 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 throught the dynamics. For details on these methods and models, see the model documentation.

params: P#
scratch: Sc#
discrete_states: S#
continuous_states: C#
isFinalized() bool[source]#

Return True if the model’s parameters are finalized. False otherwise.

class Karana.Models.BaseKModel#

Bases: Karana.Core.LockingBase

This 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 curiuosly-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#
state_propagator: Karana.Dynamics.StatePropagator#
stdDebugMsg(msg: str) None#

Print a standard debug message.

This creates json with debug information and passes it to the debug logger.

Parameter msg:

The message to log.

class Karana.Models.CppKModelContinuousStates#

Bases: Karana.Core.Base

A base class for continuous model states. Derive from this and add any continuous states for your model.

Override the isFinalized 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 continous model states.

Returns:

The continuous model states.

getdX() Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]#

Get the deriviative of the continous model states.

Returns:

The continuous model states’ derivatives.

setX(x: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]) None#

Set the continous model states.

Parameter x:

The new continuous model states.

class Karana.Models.KModelContinuousStates(name: str)#

Bases: CppKModelContinuousStates

A base class for continuous model states. Derive from this and add any continuous states for your model.

Override the isFinalized 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: Karana.Core.Base

A base class for discrete model states. Derive from this and add any parameters for your model. Override the isFinalized 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: Karana.Core.Base

class Karana.Models.PyKModelBase(name: str, sp: Karana.Dynamics.StatePropagator)#

Bases: BaseKModel

KModel<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#
state_propagator: Karana.Dynamics.StatePropagator#
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:
  1. The period is 0 and no nextStepEndTime method is defined. In this case, the pre/postModelStep methods will run every time a simulation hop happens.

  2. The period is non-zero. In this case, the pre/postModelStep methods will run at the specified period.

  3. The period is 0 and a nextStepEndTime method is defined. In this case, the nextStepEndTime 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 nextStepEndTime 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 nextStepEndTime 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: 1. 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. 2. The period is non-zero. In this case, the begin/postModelStep methods will run at the specified period. 3. 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.

Parameter t:
  • The new model period.

class Karana.Models.ComputedTorque(name: str, sp: Karana.Dynamics.StatePropagator, st: Karana.Dynamics.SubTree, set_accels_fn: collections.abc.Callable[[float | numpy.timedelta64, Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]], None])#

Bases: ComputedTorqueKModel

Limits the generalized force that can be applied to a subhinge.

static create(name: str, sp: Karana.Dynamics.StatePropagator, 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.

Parameter name:

The name of the model.

Parameter sp:

The StatePropagator to register this model with.

Parameter st:

The SubTree to apply the torques to.

Parameter 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.

Parameter t:

Current time. This is passed to the user-supplied set_accels_fn.

Parameter x:

Current state. This is passed to the user-supplied set_accels_fn.

class Karana.Models.ComputedTorqueKModel#

Bases: Karana.Models.BaseKModel

debug_model: bool#
state_propagator: Karana.Dynamics.StatePropagator#
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

isFinalized() bool#

Checks whether the model is finalized.

Returns:

Returns false if the params pointer is emtpy 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:

  1. 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.

  2. The period is non-zero. In this case, those methods will run at the specified period.

  3. 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, sp: Karana.Dynamics.StatePropagator, h5_writer: Karana.KUtils.H5Writer)#

Bases: DataLoggerKModel

The DataLogger model updates the visualization at each postHop.

static create(name: str, sp: Karana.Dynamics.StatePropagator, h5_writer: Karana.KUtils.H5Writer) DataLogger#

Constructor.

Parameter name:

The name of the DataLogger model.

Parameter sp:

The StatePropagator to register this model with.

Parameter 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.

Parameter t:

Current time. Not used.

Parameter x:

Current state. Not used.

class Karana.Models.DataLoggerKModel#

Bases: Karana.Models.BaseKModel

debug_model: bool#
params: DataLoggerParams#
state_propagator: Karana.Dynamics.StatePropagator#
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

isFinalized() bool#

Checks whether the model is finalized.

Returns:

Returns false if the params pointer is emtpy 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:

  1. 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.

  2. The period is non-zero. In this case, those methods will run at the specified period.

  3. 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.

isFinalized() bool#

Used to ensure the params are finalized.

Returns:

true if the params are finalized, `false otherwise.

property log_first_step: bool#

If true, then log the first step.

class Karana.Models.GraphicalSceneMovie(name: str, sp: Karana.Dynamics.StatePropagator, scene: Karana.Scene.ProxyScene)#

Bases: GraphicalSceneMovieKModel

The GraphicalSceneMovie model updates the visualization at each postHop.

static create(name: str, sp: Karana.Dynamics.StatePropagator, scene: Karana.Scene.ProxyScene) GraphicalSceneMovie#

Constructor.

Parameter name:

The name of the GraphicalSceneMovie model.

Parameter sp:

The StatePropagator to register this model with.

Parameter 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.

Parameter t:

Current time. Not used.

Parameter x:

Current state. Not used.

class Karana.Models.GraphicalSceneMovieKModel#

Bases: Karana.Models.BaseKModel

debug_model: bool#
params: GraphicalSceneMovieParams#
state_propagator: Karana.Dynamics.StatePropagator#
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

isFinalized() bool#

Checks whether the model is finalized.

Returns:

Returns false if the params pointer is emtpy 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:

  1. 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.

  2. The period is non-zero. In this case, those methods will run at the specified period.

  3. 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.

isFinalized() bool#

Used to ensure the params are finalized.

Returns:

true if the params are finalized, `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.PID(name: str, sp: Karana.Dynamics.StatePropagator, 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: PIDKModel

Simple PID controller model.

static create(name: str, sp: Karana.Dynamics.StatePropagator, 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.

Parameter name:

The name of the model.

Parameter sp:

The StatePropagator to register this model with.

Parameter sh:

The Subhinge to apply the forces calculated by the PID controller to.

Parameter q_traj:

A function that defines the reference trajectory for Q.

Parameter 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.

Parameter t:

Current time.

Parameter 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.

Parameter t:

Current time.

Parameter x:

Current state. Not used.

class Karana.Models.PIDKModel#

Bases: Karana.Models.BaseKModel

debug_model: bool#
params: PIDParams#
state_propagator: Karana.Dynamics.StatePropagator#
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

isFinalized() bool#

Checks whether the model is finalized.

Returns:

Returns false if the params pointer is emtpy 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:

  1. 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.

  2. The period is non-zero. In this case, those methods will run at the specified period.

  3. 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.

isFinalized() bool#

Used to ensure the params are finalized.

Returns:

true if the params are finalized, `false otherwise.

property kd: float#

Derivative gain

property ki: float#

Integral gain

property kp: float#

Proportional gain

class Karana.Models.PinJointLimits(name: str, sp: Karana.Dynamics.StatePropagator, pin: Karana.Dynamics.PinSubhinge)#

Bases: PinJointLimitsKModel

Model that adds joint limits to a pin hinge.

static create(name: str, sp: Karana.Dynamics.StatePropagator, pin: Karana.Dynamics.PinSubhinge) PinJointLimits#

Constructor.

Parameter name:

The name of the model.

Parameter sp:

The StatePropagator to register this model with.

Parameter 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.

Parameter t:
  • Current time. Not used.

Parameter x:
  • Current state. Not used.

class Karana.Models.PinJointLimitsKModel#

Bases: Karana.Models.BaseKModel

debug_model: bool#
params: PinJointLimitsParams#
state_propagator: Karana.Dynamics.StatePropagator#
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

isFinalized() bool#

Checks whether the model is finalized.

Returns:

Returns false if the params pointer is emtpy 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:

  1. 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.

  2. The period is non-zero. In this case, those methods will run at the specified period.

  3. 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.

isFinalized() bool#

Used to ensure the params are finalized.

Returns:

true if the params are finalized, `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, sp: Karana.Dynamics.StatePropagator, st: Karana.Dynamics.SubTree, central_body: Karana.Frame.Frame)#

Bases: PointMassGravityKModel

Model to compute and apply uniform gravity accelearation from a point mass central body to all the bodies in the multibody system.

static create(name: str, sp: Karana.Dynamics.StatePropagator, st: Karana.Dynamics.SubTree, central_body: Karana.Frame.Frame) PointMassGravity#

Constructor.

Parameter name:

The name of the model.

Parameter sp:

The StatePropagator to register this model with.

Parameter st:

The SubTree to apply gravity to.

Parameter central_body:

The point mass central body applying the gravitational force

Returns:

A ks_ptr to the newly created instance of the PointMassGravity model.

getObjIds() list[int]#

Get node IDs for DataStruct.

This method retrieves the IDs of the multibody and central body. This is designed primarily for use with the PointMassGravityDS DataStruct.

Returns:

mbody and central body IDs.

preDeriv(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#

Calculate and apply the aerodynamic force.

Parameter t:
  • Current time. Not used.

Parameter x:
  • Current state. Not used.

class Karana.Models.PointMassGravityKModel#

Bases: Karana.Models.BaseKModel

debug_model: bool#
params: PointMassGravityParams#
state_propagator: Karana.Dynamics.StatePropagator#
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

isFinalized() bool#

Checks whether the model is finalized.

Returns:

Returns false if the params pointer is emtpy 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:

  1. 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.

  2. The period is non-zero. In this case, those methods will run at the specified period.

  3. 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.PointMassGravityDS#

Create a PointMassGravityDS from this PointMassGravity model.

Returns:

  • PointMassGravityDS

  • A PointMassGravityDS instance with values set to match this model.

class Karana.Models.PointMassGravityParams#

Parameters for the PointMassGravity model.

isFinalized() bool#

Used to ensure the params are finalized.

Returns:

true if the params are finalized, `false otherwise.

property mu: float#

m^3/(kg s^2) )

Type:

Gravitational constant (units

class Karana.Models.ProjectConstraintError(name: str, sp: Karana.Dynamics.StatePropagator, sg: Karana.Dynamics.SubGraph, integrator: Karana.Math.Integrator, cks: Karana.Dynamics.ConstraintKinematicsSolver)#

Bases: ProjectConstraintErrorKModel

The ProjectConstraintError model updates the visualization at each postHop.

static create(name: str, sp: Karana.Dynamics.StatePropagator, sg: Karana.Dynamics.SubGraph, integrator: Karana.Math.Integrator, cks: Karana.Dynamics.ConstraintKinematicsSolver) ProjectConstraintError#

Constructor.

Parameter name:

The name of the ProjectConstraintError model.

Parameter sp:

The StatePropagator to register this model with.

Parameter sg:

The SubGraph whose coordinates will be projected.

Parameter cks:

The ConstraintKinematicsSolver used to do the projection.

Parameter 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.

Parameter t:

Current time. Used when doing the integrator soft reset.

Parameter x:

Current state. This is used to calcualte the error and is the state used to project from if a projection is needed.

class Karana.Models.ProjectConstraintErrorKModel#

Bases: Karana.Models.BaseKModel

debug_model: bool#
params: ProjectConstraintErrorParams#
state_propagator: Karana.Dynamics.StatePropagator#
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

isFinalized() bool#

Checks whether the model is finalized.

Returns:

Returns false if the params pointer is emtpy 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:

  1. 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.

  2. The period is non-zero. In this case, those methods will run at the specified period.

  3. 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.

isFinalized() bool#

Used to ensure the params are finalized.

Returns:

true if the params are finalized, `false otherwise.

property tol: float#

Directory where the renders will be saved.

class Karana.Models.SpringDamper(name: str, sp: Karana.Dynamics.StatePropagator, nd1: Karana.Dynamics.Node, nd2: Karana.Dynamics.Node)#

Bases: SpringDamperKModel

Adds a spring-damper between two nodes.

static create(name: str, sp: Karana.Dynamics.StatePropagator, 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.

Parameter name:

The name of the model.

Parameter sp:

The StatePropagator to register this model with.

Parameter nd1:

The first node in the spring damper model.

Parameter nd2:

The second node in the spring damper model.

Returns:

A ks_ptr to the newly created instance of the SpringDamper model.

getDampingForce() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Get the linear force due to damping

Returns:

The force

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.

getPositionError() float#

Get the signed length offset from unsprung length

Returns:

The error

getStiffnessForce() float#

Get the signed scalar force due to stiffness

Returns:

The force

getTotalForce() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Get the overall spring force

Returns:

The force

getVelocityError() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Get the relative linear velocity

Returns:

The relative velocity

preDeriv(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#

Calculate and apply the spring/damper force.

Parameter t:

Current time. Not used.

Parameter 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#
params: SpringDamperParams#
state_propagator: Karana.Dynamics.StatePropagator#
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

isFinalized() bool#

Checks whether the model is finalized.

Returns:

Returns false if the params pointer is emtpy 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:

  1. 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.

  2. The period is non-zero. In this case, those methods will run at the specified period.

  3. 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.

isFinalized() bool#

Used to ensure the params are finalized.

Returns:

true if the params are finalized, `false otherwise.

property d: float#

Damper constant

property k: float#

Spring constant

property unsprung_length: float#

Unsprung length

class Karana.Models.SubhingeForceLimits(name: str, sp: Karana.Dynamics.StatePropagator, sh: Karana.Dynamics.PhysicalSubhinge)#

Bases: SubhingeForceLimitsKModel

Limits the generalized force that can be applied to a subhinge.

static create(name: str, sp: Karana.Dynamics.StatePropagator, 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.

Parameter name:

The name of the model.

Parameter sp:

The StatePropagator to register this model with.

Parameter 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.

Parameter t:

Current time. Not used.

Parameter x:

Current state. Not used.

class Karana.Models.SubhingeForceLimitsKModel#

Bases: Karana.Models.BaseKModel

debug_model: bool#
params: SubhingeForceLimitsParams#
state_propagator: Karana.Dynamics.StatePropagator#
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

isFinalized() bool#

Checks whether the model is finalized.

Returns:

Returns false if the params pointer is emtpy 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:

  1. 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.

  2. The period is non-zero. In this case, those methods will run at the specified period.

  3. 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#

Paramters for the SubhingeForceLimits model.

isFinalized() bool#

Used to ensure the params are finalized.

Returns:

true if the params are finalized, `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, sp: Karana.Dynamics.StatePropagator, sh: Karana.Dynamics.PhysicalSubhinge)#

Bases: SubhingeSpringDamperKModel

Adds a spring damper to the provided subhinge.

static create(name: str, sp: Karana.Dynamics.StatePropagator, sh: Karana.Dynamics.PhysicalSubhinge) SubhingeSpringDamper#

Constructor. The SubhingeSpringDamper model a spring damper force to a subhinge based on a given setpoint.

Parameter name:

The name of the model.

Parameter sp:

The StatePropagator to register this model with.

Parameter 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.

Parameter t:

Current time. Not used.

Parameter x:

Current state. Not used.

class Karana.Models.SubhingeSpringDamperKModel#

Bases: Karana.Models.BaseKModel

debug_model: bool#
params: SubhingeSpringDamperParams#
state_propagator: Karana.Dynamics.StatePropagator#
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

isFinalized() bool#

Checks whether the model is finalized.

Returns:

Returns false if the params pointer is emtpy 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:

  1. 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.

  2. The period is non-zero. In this case, those methods will run at the specified period.

  3. 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.

isFinalized() bool#

Used to ensure the params are finalized.

Returns:

true if the params are finalized, `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, sp: Karana.Dynamics.StatePropagator, rt_speed: SupportsFloat = 1.0)#

Bases: SyncRealTimeKModel

Limits sim speed to a multiple of real time.

static create(name: str, sp: Karana.Dynamics.StatePropagator, rt_speed: SupportsFloat = 1.0) SyncRealTime#

Constructor.

Parameter name:

The name of the model.

Parameter sp:

The StatePropagator to register this model with.

Parameter 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.

Parameter t:

Current time.

Parameter 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.

Parameter t:

Current time.

Parameter x:

Current state. Not used.

class Karana.Models.SyncRealTimeKModel#

Bases: Karana.Models.BaseKModel

debug_model: bool#
state_propagator: Karana.Dynamics.StatePropagator#
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

isFinalized() bool#

Checks whether the model is finalized.

Returns:

Returns false if the params pointer is emtpy 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:

  1. 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.

  2. The period is non-zero. In this case, those methods will run at the specified period.

  3. 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, sp: Karana.Dynamics.StatePropagator, scene: Karana.Scene.GraphicalScene)#

Bases: TimeDisplayKModel

The TimeDisplay model updates the visualization at each postHop.

static create(name: str, sp: Karana.Dynamics.StatePropagator, scene: Karana.Scene.GraphicalScene) TimeDisplay#

Constructor.

Parameter name:

The name of the model.

Parameter sp:

The StatePropagator to register this model with.

Parameter 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

Parameter t:

Current time. Not used.

Parameter x:

Current state. Not used.

class Karana.Models.TimeDisplayKModel#

Bases: Karana.Models.BaseKModel

debug_model: bool#
params: TimeDisplayParams#
state_propagator: Karana.Dynamics.StatePropagator#
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

isFinalized() bool#

Checks whether the model is finalized.

Returns:

Returns false if the params pointer is emtpy 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:

  1. 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.

  2. The period is non-zero. In this case, those methods will run at the specified period.

  3. 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#
isFinalized() bool#

Used to ensure the params are finalized.

Returns:

true if the params are finalized, false otherwise.

property color: Karana.Scene.Color#

Color of the time text

class Karana.Models.UniformGravity(name: str, sp: Karana.Dynamics.StatePropagator, st: Karana.Dynamics.SubTree)#

Bases: UniformGravityKModel

Apply uniform gravitational acceleration to each body in the provided multibody.

static create(name: str, sp: Karana.Dynamics.StatePropagator, st: Karana.Dynamics.SubTree) UniformGravity#

Constructor.

Parameter name:

The name of the model.

Parameter sp:

The StatePropagator to register this model with.

Parameter st:

The SubTree to apply uniform gravity to.

Returns:

A ks_ptr to the newly created instance of the UniformGravity model.

preDeriv(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#

Calculate and apply the aerodynamic force.

Parameter t:

Current time. Not used.

Parameter x:

Current state. Not used.

class Karana.Models.UniformGravityKModel#

Bases: Karana.Models.BaseKModel

debug_model: bool#
params: UniformGravityParams#
state_propagator: Karana.Dynamics.StatePropagator#
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

isFinalized() bool#

Checks whether the model is finalized.

Returns:

Returns false if the params pointer is emtpy 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:

  1. 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.

  2. The period is non-zero. In this case, those methods will run at the specified period.

  3. 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.UniformGravityParams#

Parameters for the UniformGravity class.

isFinalized() bool#

Used to ensure the params are finalized.

Returns:

true if the params are finalized, `false otherwise.

property g: Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Gravity vector

class Karana.Models.UpdateProxyScene(name: str, sp: Karana.Dynamics.StatePropagator, scene: Karana.Scene.ProxyScene)#

Bases: UpdateProxySceneKModel

The UpdateProxyScene model updates the visualization at each postHop.

static create(name: str, sp: Karana.Dynamics.StatePropagator, scene: Karana.Scene.ProxyScene) UpdateProxyScene#

Constructor.

Parameter name:

The name of the model.

Parameter sp:

The StatePropagator to register this model with.

Parameter 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.

Parameter t:

Current time. Not used.

Parameter x:

Current state. Not used.

class Karana.Models.UpdateProxySceneKModel#

Bases: Karana.Models.BaseKModel

debug_model: bool#
state_propagator: Karana.Dynamics.StatePropagator#
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

isFinalized() bool#

Checks whether the model is finalized.

Returns:

Returns false if the params pointer is emtpy 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:

  1. 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.

  2. The period is non-zero. In this case, those methods will run at the specified period.

  3. 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.DataPlotter(name: str, sp: Karana.Dynamics.StatePropagator)[source]#

Bases: Karana.Models.KModel

DataPlotter model.

This model updates a DashApp at the specified interval.

params: DataPlotterParams#
postModelStep(t: float | numpy.timedelta64, x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]])[source]#

Update the DashApp.

Parameters:
  • t (float | np.timedelta64) – Current time. Unused.

  • x (Annotated[ArrayLike, np.float64, '[m, 1]']) – Current state vector. Unused.

class Karana.Models.PenaltyContact(name: str, sp: Karana.Dynamics.StatePropagator, st: Karana.Dynamics.SubTree, colliders: collections.abc.Sequence[Karana.Collision.FrameCollider], default_contact_force_model: Karana.Collision.ContactForceBase)#

Bases: PenaltyContactKModel

Model applying penalty forces proportional to collision penetration

The normal force magnitude is Fn = max(0, (kp*p^n + kc*p^n*v)), where kp, kc, and n are as defined in the parameters and v is the velocity in the normal direction.

The tangential force magnitude is mu*Fn where mu is as defined in the parameters and Fn is the normal force magnitude defined above.

static create(name: str, sp: Karana.Dynamics.StatePropagator, st: Karana.Dynamics.SubTree, colliders: collections.abc.Sequence[Karana.Collision.FrameCollider], default_contact_force_model: Karana.Collision.ContactForceBase) PenaltyContact#

Create a PenaltyContact model.

Parameter name:
  • The name of the model.

Parameter sp:

The StatePropagator to register this model with.

Parameter st:
  • The SubTree that this model is operating on.

Parameter colliders:
  • Helpers to generate body contacts.

Parameter contact_force_model:
  • The model used for computing contact forces.

Returns:

The created PenaltyContact model.

preDeriv(name: float | numpy.timedelta64, collider: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#

Apply penalty contact forces.

Parameter t:
  • Current time. Not used.

Parameter x:
  • Current state. Not used.

class Karana.Models.PenaltyContactKModel#

Bases: Karana.Models.BaseKModel

debug_model: bool#
state_propagator: Karana.Dynamics.StatePropagator#
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

isFinalized() bool#

Checks whether the model is finalized.

Returns:

Returns false if the params pointer is emtpy 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:

  1. 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.

  2. The period is non-zero. In this case, those methods will run at the specified period.

  3. 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.