StateVariable Class


The StateVariable wraps a state and its derivative. It is used by classes inheriting from DynamicSimComponent. More...

Header: #include <StateVariable>
Inherits: CDP::StudioAPI::CDPNode

Public Functions

virtual ~StateVariable() override
virtual void Configure(XMLElementEx *pStateVariableXML)
virtual void Create(const char *name, DynamicSimComponent *parent)
void OverrideStateValue(double newValue)
virtual void UpdateValueFromConfiguration()
operator double() const

Reimplemented Public Functions

virtual void FillNodeChildren(CDP::StudioAPI::NodeStream &serializer) const override
virtual const std::string GetNodeName() const override
virtual std::string GetNodeTypeName() const override
virtual CDP::StudioAPI::CDPValueType GetNodeValueType() const override
virtual CDP::StudioAPI::CDPVariantValue GetVariantValue() const override

Additional Inherited Members

Detailed Description

The StateVariable wraps a state and its derivative. It is used by classes inheriting from DynamicSimComponent.


Instantiate as a member of a parent DynamicSimComponent in the header file and call Create() during initialization.

To read "the state", use the object as if it is a double (e.g. "Output = x;"). To write "the state", use the OverrideStateValue() function (e.g. "x.OverrideStateValue(0);"). To read or write "the state's derivative" (usually done in simulator component DynamicSimComponent::EvaluateDiffEquations() method), read or write the .ddt member (e.g. "x.ddt = v;").


In the class declaration:

CDPSim::StateVariable x, v;

In the implementation file: In Create(...):

x.Create("x", this);
v.Create("v", this);

In EvaluateDiffEquations(...):

x.ddt = v;    // Set "x's derivative" to "v's state".
v.ddt = F/m;

In PostIntegrate(...):

if (x < 0)  // Simulate a wall at x==0
    v.OverrideStateValue(0); // Reset speed to 0 after hitting a wall
    x.ddt = 0;

Member Function Documentation


Default constructs an instance of StateVariable.

[override virtual] StateVariable::~StateVariable()

Destroys the instance of StateVariable. The destructor is virtual.

[virtual] void StateVariable::Configure(XMLElementEx *pStateVariableXML)

Reads configuration from XML. Called automatically by parent DynamicSimComponent.

[virtual] void StateVariable::Create(const char *name, DynamicSimComponent *parent)

Creates the instance, binds it to name and registers to parent.

[override virtual] void StateVariable::FillNodeChildren(CDP::StudioAPI::NodeStream &serializer) const

Reimplemented from CDPNode::FillNodeChildren().

Exposes child nodes of this node to StudioAPI.

[override virtual] const std::string StateVariable::GetNodeName() const

Reimplemented from CDPNode::GetNodeName().

Returns node's unique name.

[override virtual] std::string StateVariable::GetNodeTypeName() const

Reimplemented from CDPNode::GetNodeTypeName().

Returns node's model name.

[override virtual] CDP::StudioAPI::CDPValueType StateVariable::GetNodeValueType() const

Reimplemented from CDPNode::GetNodeValueType().

Returns node's value type which is double.

[override virtual] CDP::StudioAPI::CDPVariantValue StateVariable::GetVariantValue() const

Reimplemented from CDPNode::GetVariantValue().

Returns node's value.

void StateVariable::OverrideStateValue(double newValue)

Use this method to override the state variable's value to something else than what the simulator calculates. This can be done in DynamicSimComponent::Reset(), DynamicSimComponent::PreIntegrate() or DynamicSimComponent::PostIntegrate().

This method should not be called from DynamicSimComponent::EvaluateDiffEquations().

[virtual] void StateVariable::UpdateValueFromConfiguration()

Resets value to initial value read from configuration.

StateVariable::operator double() const

Returns the state variable's value.