Skip to content
StateSpaceTest.md

StateSpaceTest

Test component for StateSpace block demonstrating basic functionality.

Creates a simple test system with:

  • A step input signal

  • A second-order state space system

  • Integration of the output for verification

The state space system represents a second-order system with:

  • States: position and velocity

  • Single input: force/acceleration

  • Single output: position

  • Operating point offset to test that feature

Usage

StateSpaceTest()

Behavior

[connect(step+y(t),getindex(statespace+u(t),1))connect(getindex(statespace+y(t),1),integrator+u(t))connect(integrator+y(t),terminator+u(t))step.y(t)=ifelse(tstep.start_time,step.height+step.offset,step.offset)state_space.Δu(t)=broadcast(,state_space.u(t),state_space.u0)state_space.Δy(t)=broadcast(,state_space.y(t),state_space.y0)dstate_space.x(t)dt=broadcast(+,state_space.Astate_space.x(t),state_space.Bstate_space.Δu(t))state_space.Δy(t)=broadcast(+,state_space.Cstate_space.x(t),state_space.Dstate_space.Δu(t))dintegrator.x(t)dt=integrator.kintegrator.u(t)integrator.y(t)=integrator.x(t)]

Source

dyad
# Test component for StateSpace block demonstrating basic functionality.
#
# Creates a simple test system with:
# - A step input signal
# - A second-order state space system
# - Integration of the output for verification
#
# The state space system represents a second-order system with:
# - States: position and velocity
# - Single input: force/acceleration
# - Single output: position
# - Operating point offset to test that feature
component StateSpaceTest
  # Step input signal starting at time 1.0 with amplitude 2.0
  step = BlockComponents.Step(height=2.0, start_time=1.0)
  # Second-order state space system
  # Represents: d²x/dt² + 2*damping*freq*dx/dt + freq²*x = freq²*u
  # In state space form with x1=position, x2=velocity:
  # dx1/dt = x2
  # dx2/dt = -freq²*x1 - 2*damping*freq*x2 + freq²*u
  # y = x1 (output position)
  state_space = BlockComponents.StateSpace(nx=2, nu=1, ny=1, A=reshape([0.0, 1.0, -4.0, -2.0], 2, 2), B=reshape([0.0, 4.0], 2, 1), C=reshape([1.0, 0.0], 1, 2), D=reshape([0.0], 1, 1), x0=[0.5, 0.0], u0=[0.5], y0=[0.1])
  # Integrator to accumulate the output for testing
  integrator = BlockComponents.Integrator(k=1.0, x0=0.0)
  # Terminator for the integrated signal
  terminator = BlockComponents.Terminator()
relations
  # Connect step input to state space system
  connect(step.y, state_space.u[1])
  # Connect state space output to integrator
  connect(state_space.y[1], integrator.u)
  # Connect integrator output to terminator
  connect(integrator.y, terminator.u)
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 5,
        "expect": {
          "signals": ["integrator.y"],
          "initial": {"integrator.y": 0},
          "final": {"integrator.y": -18.288754189661404}
        }
      }
    }
  }
}
end
Flattened Source
dyad
# Test component for StateSpace block demonstrating basic functionality.
#
# Creates a simple test system with:
# - A step input signal
# - A second-order state space system
# - Integration of the output for verification
#
# The state space system represents a second-order system with:
# - States: position and velocity
# - Single input: force/acceleration
# - Single output: position
# - Operating point offset to test that feature
component StateSpaceTest
  # Step input signal starting at time 1.0 with amplitude 2.0
  step = BlockComponents.Step(height=2.0, start_time=1.0)
  # Second-order state space system
  # Represents: d²x/dt² + 2*damping*freq*dx/dt + freq²*x = freq²*u
  # In state space form with x1=position, x2=velocity:
  # dx1/dt = x2
  # dx2/dt = -freq²*x1 - 2*damping*freq*x2 + freq²*u
  # y = x1 (output position)
  state_space = BlockComponents.StateSpace(nx=2, nu=1, ny=1, A=reshape([0.0, 1.0, -4.0, -2.0], 2, 2), B=reshape([0.0, 4.0], 2, 1), C=reshape([1.0, 0.0], 1, 2), D=reshape([0.0], 1, 1), x0=[0.5, 0.0], u0=[0.5], y0=[0.1])
  # Integrator to accumulate the output for testing
  integrator = BlockComponents.Integrator(k=1.0, x0=0.0)
  # Terminator for the integrated signal
  terminator = BlockComponents.Terminator()
relations
  # Connect step input to state space system
  connect(step.y, state_space.u[1])
  # Connect state space output to integrator
  connect(state_space.y[1], integrator.u)
  # Connect integrator output to terminator
  connect(integrator.y, terminator.u)
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 5,
        "expect": {
          "signals": ["integrator.y"],
          "initial": {"integrator.y": 0},
          "final": {"integrator.y": -18.288754189661404}
        }
      }
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

  • Examples

  • Experiments

  • Analyses