Class BaseKModel#

Inheritance Relationships#

Base Type#

Derived Types#

Class Documentation#

class BaseKModel : public 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.

Subclassed by Karana::Models::KModel< ComputedTorque >, Karana::Models::KModel< DataLogger, DataLoggerParams >, Karana::Models::KModel< GraphicalSceneMovie, GraphicalSceneMovieParams >, Karana::Models::KModel< PID, PIDParams >, Karana::Models::KModel< PenaltyContact >, Karana::Models::KModel< PinJointLimits, PinJointLimitsParams >, Karana::Models::KModel< PointMassGravity, PointMassGravityParams >, Karana::Models::KModel< ProjectConstraintError, ProjectConstraintErrorParams >, Karana::Models::KModel< SpringDamper, SpringDamperParams >, Karana::Models::KModel< SubhingeForceLimits, SubhingeForceLimitsParams >, Karana::Models::KModel< SubhingeSpringDamper, SubhingeSpringDamperParams >, Karana::Models::KModel< SyncRealTime >, Karana::Models::KModel< TimeDisplay, TimeDisplayParams >, Karana::Models::KModel< UniformGravity, UniformGravityParams >, Karana::Models::KModel< UpdateProxyScene >, Karana::Models::KModel< T, P, Sc, S, C >

Public Functions

BaseKModel(std::string_view name, const kc::ks_ptr<kd::StatePropagator> &sp)#

Constructor

virtual std::optional<km::Ktime> getNextModelStepTime(const km::Ktime &t) = 0#

Get the next step time assuming that the provided time t is a time the model has a step at.

Parameters:

t – - A time the model has a step at.

Returns:

The next step time. If std::nullopt, then the model has no more step times.

virtual km::Ktime getPeriod() = 0#

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.

virtual void setPeriod(const km::Ktime &t) = 0#

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.

Parameters:

t – - The new model period.

virtual void stdDebugMsg(std::string_view msg)#

Print a standard debug message.

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

Parameters:

msg – The message to log.

Public Members

kc::ks_ptr<kd::StatePropagator> state_propagator#

The StatePropagator associated with this KModel.

bool debug_model = false#

debug_model is a member variable used to enable/disable debug statements for this model.

Protected Functions

virtual void _registerModel() = 0#

Register the model with StatePropagator.

virtual void _unregisterModel() = 0#

Unregister the model with the StatePropagator.

virtual const Eigen::Ref<const km::Vec> _getContinuousStates() const = 0#
virtual const Eigen::Ref<const km::Vec> _getContinuousStatesDeriv() = 0#

Get the derivative of the continuous states. Overriden by KModel if appropriate.

Returns:

The model’s continuous states’ derivatives.

virtual void _setContinuousStates(const Eigen::Ref<const km::Vec> x) = 0#

Set the continous model states.

Parameters:

x – The new continuous model states.

Protected Attributes

km::Ktime period = {0}#

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.

bool _registered = false#

Boolean to track whether this model has been registered or not.

bool _has_continuous_states = false#

Boolean to track whether this model has continuous states or not. This is set in _registerModel.

Friends

friend class kd::StatePropagator