Skip to content
LIBRARY
Examples.Integrator.SimpleDiscreteIntegrator.md

Examples.Integrator.SimpleDiscreteIntegrator ​

Usage ​

DiscreteComponents.Examples.Integrator.SimpleDiscreteIntegrator()

Parameters: ​

NameDescriptionUnitsDefault value
dt–0.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 ​

Source ​

dyad
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.Math.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.Math.Product() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 590, "y1": 490, "x2": 690, "y2": 590, "rot": 0}
      },
      "tags": []
    }
  }
  structural parameter 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
dyad
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.Math.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.Math.Product() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 590, "y1": 490, "x2": 690, "y2": 590, "rot": 0}
      },
      "tags": []
    }
  }
  structural parameter 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.