SimpleDiscreteIntegrator SimpleDiscreteIntegrator Icon

Examples.SimpleDiscreteIntegrator

Usage

DiscreteComponents.Examples.SimpleDiscreteIntegrator()

Parameters:

NameDescriptionUnitsDefault value
dt0.1

Connectors

  • u - This connector represents a real signal as an input to a component (RealInput)
  • y - This connector represents a real signal as an output from a component (RealOutput)

Variables

NameDescriptionUnits
reset_value

Behavior

\[ \begin{equation} \left[ \begin{array}{c} \mathrm{connect}\left( y(t), unitdelay_{+}u(t) \right) \\ \mathrm{connect}\left( unitdelay_{+}y(t), add_{+}u1(t) \right) \\ \mathrm{connect}\left( add_{+}y(t), y(t) \right) \\ \mathrm{connect}\left( u(t), product_{+}u1(t) \right) \\ \mathrm{connect}\left( sampletimeblock_{+}y(t), product_{+}u2(t) \right) \\ \mathrm{connect}\left( product_{+}y(t), add_{+}u2(t) \right) \\ \mathtt{unitdelay.y}\left( t \right) = Shift(t, -1)\left( \mathtt{unitdelay.u}\left( t \right) \right) \\ \frac{\mathrm{d} \mathtt{unitdelay.dummy.dummy}\left( t \right)}{\mathrm{d}t} = 0 \\ \mathtt{add.y}\left( t \right) = \mathtt{add.k1} \mathtt{add.u1}\left( t \right) + \mathtt{add.k2} \mathtt{add.u2}\left( t \right) \\ \mathtt{sampletimeblock.y}\left( t \right) = ModelingToolkit.SampleTime \\ \mathtt{product.y}\left( t \right) = \mathtt{product.u2}\left( t \right) \mathtt{product.u1}\left( t \right) \\ \end{array} \right] \end{equation} \]

Source

component SimpleDiscreteIntegrator@[input clk]
  u = RealInput@[clk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -50, "y1": 450, "x2": 50, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  y = RealOutput@[clk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 960, "y1": 450, "x2": 1060, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  unitdelay = DiscreteComponents.UnitDelay() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 900, "y1": 290, "x2": 800, "y2": 390, "rot": 0}
      },
      "tags": []
    }
  }
  add = BlockComponents.Add() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 790, "y1": 450, "x2": 890, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  sampletimeblock = DiscreteComponents.SampleTimeSource() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 430, "y1": 610, "x2": 530, "y2": 710, "rot": 0}
      },
      "tags": []
    }
  }
  product = BlockComponents.Product() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 590, "y1": 490, "x2": 690, "y2": 590, "rot": 0}
      },
      "tags": []
    }
  }
  structural dt::Real = 0.1
  variable reset_value::Real = NaN
relations
  """
    y@(clk) = ifelse(reset > 0.0, sample(reset_value, clk), y@(clk-1) + u(clk) * dt)
    reset_value@(clk) = ifelse(
      isnan_wrapper(sample(reset_value, clk)@(clk-1)),
      ic@(clk),
      reset_value@(clk-1)
    )
  """
  initial u@(clk-1) = 0.0
  initial reset_value@(clk-1) = 0.0
  initial y@(clk-1) = 0.0
  connect(unitdelay.u, y) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 1010, "y": 340}], "E": 2}]
    }
  }
  connect(unitdelay.y, add.u1) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 640, "y": 340}, {"x": 640, "y": 470}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(add.y, y) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
  connect(u, product.u1) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 0, "y": 510}], "E": 2}]
    }
  }
  connect(product.u2, sampletimeblock.y) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 558, "y": 570}, {"x": 558, "y": 660}], "E": 2}]
    }
  }
  connect(product.y, add.u2) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 740, "y": 540}, {"x": 740, "y": 530}], "E": 2}]
    }
  }
end
Flattened Source
component SimpleDiscreteIntegrator
  u = RealInput@[clk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -50, "y1": 450, "x2": 50, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  y = RealOutput@[clk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 960, "y1": 450, "x2": 1060, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  unitdelay = DiscreteComponents.UnitDelay() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 900, "y1": 290, "x2": 800, "y2": 390, "rot": 0}
      },
      "tags": []
    }
  }
  add = BlockComponents.Add() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 790, "y1": 450, "x2": 890, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  sampletimeblock = DiscreteComponents.SampleTimeSource() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 430, "y1": 610, "x2": 530, "y2": 710, "rot": 0}
      },
      "tags": []
    }
  }
  product = BlockComponents.Product() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 590, "y1": 490, "x2": 690, "y2": 590, "rot": 0}
      },
      "tags": []
    }
  }
  structural dt::Real = 0.1
  variable reset_value::Real = NaN
relations
  """
    y@(clk) = ifelse(reset > 0.0, sample(reset_value, clk), y@(clk-1) + u(clk) * dt)
    reset_value@(clk) = ifelse(
      isnan_wrapper(sample(reset_value, clk)@(clk-1)),
      ic@(clk),
      reset_value@(clk-1)
    )
  """
  initial u@(clk-1) = 0.0
  initial reset_value@(clk-1) = 0.0
  initial y@(clk-1) = 0.0
  connect(unitdelay.u, y) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 1010, "y": 340}], "E": 2}]
    }
  }
  connect(unitdelay.y, add.u1) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 640, "y": 340}, {"x": 640, "y": 470}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(add.y, y) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
  connect(u, product.u1) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 0, "y": 510}], "E": 2}]
    }
  }
  connect(product.u2, sampletimeblock.y) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 558, "y": 570}, {"x": 558, "y": 660}], "E": 2}]
    }
  }
  connect(product.y, add.u2) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 740, "y": 540}, {"x": 740, "y": 530}], "E": 2}]
    }
  }
metadata {}
end


Test Cases

No test cases defined.