---
url: /dyad/dev/stdlib/DiscreteComponents/tests/Examples.SimpleRelayControl.md
description: >-
  Dyad Examples.SimpleRelayControl docs. 
  DiscreteComponents.Examples.SimpleRelayControl()
---

# `Examples.SimpleRelayControl` {#Examples.SimpleRelayControl}

## Usage {#Usage}

`DiscreteComponents.Examples.SimpleRelayControl()`

## Behavior {#Behavior}

$$ \begin{align}
0 &= \mathrm{connect}\left( zeroorderhold\_{+}y, secondorder\_{+}u \right) \\
0 &= \mathrm{connect}\left( secondorder\_{+}y, sampler\_{+}u \right) \\
0 &= \mathrm{connect}\left( discretebinarycontroller\_{+}y, zeroorderhold\_{+}u \right) \\
0 &= \mathrm{connect}\left( sampler\_{+}y, discretebinarycontroller\_{+}u\_{m}, periodicclock\_{+}y \right) \\
0 &= \mathrm{connect}\left( reference\_{+}y, discretebinarycontroller\_{+}u\_{s} \right) \\
\mathtt{discretebinarycontroller.s}\left( t \right) &= ifelse\left( Shift(t, -1)\left( \mathtt{discretebinarycontroller.s}\left( t \right) \right), \mathtt{discretebinarycontroller.u_m}\left( t \right) < \frac{\mathtt{discretebinarycontroller.b}}{2} + \mathtt{discretebinarycontroller.u_s}\left( t \right), \mathtt{discretebinarycontroller.u_m}\left( t \right) <  - \frac{1}{2} ~ \mathtt{discretebinarycontroller.b} + \mathtt{discretebinarycontroller.u_s}\left( t \right) \right) \\
\mathtt{discretebinarycontroller.y}\left( t \right) &= ifelse\left( \mathtt{discretebinarycontroller.s}\left( t \right), \mathtt{discretebinarycontroller.k},  - \mathtt{discretebinarycontroller.k} \right) \\
\frac{\mathrm{d}\mathtt{secondorder.x}\left( t \right)}{\mathrm{d}t} &= \mathtt{secondorder.xd}\left( t \right) \\
\frac{\mathrm{d}\mathtt{secondorder.xd}\left( t \right)}{\mathrm{d}t} &= \left(  - 2 ~ \mathtt{secondorder.d} ~ \mathtt{secondorder.xd}\left( t \right) + \left(  - \mathtt{secondorder.x}\left( t \right) + \mathtt{secondorder.k} ~ \mathtt{secondorder.u}\left( t \right) \right) ~ \mathtt{secondorder.w} \right) ~ \mathtt{secondorder.w} \\
\mathtt{secondorder.y}\left( t \right) &= \mathtt{secondorder.x}\left( t \right) \\
\mathtt{reference.y}\left( t \right) &= \mathtt{reference.k} \\
\mathtt{zeroorderhold.y}\left( t \right) &= Hold()\left( \mathtt{zeroorderhold.u}\left( t \right) \right) \\
\mathtt{sampler.y}\left( t \right) &= Sample(InferredClock.InferredDiscrete(0))\left( \mathtt{sampler.u}\left( t \right) \right)
\end{align}
$$

## Source {#Source}

```dyad
test component SimpleRelayControl
  discretebinarycontroller = DiscreteComponents.DiscreteBinaryController(k = 2, bool = false, b = 0.05) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 360, "y1": 340, "x2": 460, "y2": 440, "rot": 0}
      },
      "tags": []
    }
  }
  secondorder = BlockComponents.Continuous.SecondOrder() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 720, "y1": 340, "x2": 820, "y2": 440, "rot": 0}
      },
      "tags": []
    }
  }
  reference = BlockComponents.Sources.Constant(k = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 140, "y1": 320, "x2": 240, "y2": 420, "rot": 0}
      },
      "tags": []
    }
  }
  zeroorderhold = DiscreteComponents.ZeroOrderHold() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 550, "y1": 340, "x2": 650, "y2": 440, "rot": 0}
      },
      "tags": []
    }
  }
  sampler = DiscreteComponents.Sampler() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 650, "y1": 520, "x2": 550, "y2": 620, "rot": 0}
      },
      "tags": []
    }
  }
  periodicclock = DiscreteComponents.PeriodicClock(dt = 0.2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 550, "y1": 670, "x2": 650, "y2": 770, "rot": 0}
      },
      "tags": []
    }
  }
relations
  initial secondorder.x = 0.0
  initial secondorder.xd = 0.0
  connect(zeroorderhold.y, secondorder.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(secondorder.y, sampler.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 860, "y": 390}, {"x": 860, "y": 570}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(discretebinarycontroller.y, zeroorderhold.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sampler.y, discretebinarycontroller.u_m, periodicclock.y) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [], "E": -1},
        {"S": -1, "M": [{"x": 290, "y": 570}, {"x": 290, "y": 409}], "E": 2},
        {"S": 3, "M": [{"x": 470, "y": 720}], "E": -1}
      ],
      "junctions": [{"x": 470, "y": 570}],
      "renderStyle": "standard"
    }
  }
  connect(reference.y, discretebinarycontroller.u_s) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
end
```

```dyad
test component SimpleRelayControl
  discretebinarycontroller = DiscreteComponents.DiscreteBinaryController(k = 2, bool = false, b = 0.05) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 360, "y1": 340, "x2": 460, "y2": 440, "rot": 0}
      },
      "tags": []
    }
  }
  secondorder = BlockComponents.Continuous.SecondOrder() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 720, "y1": 340, "x2": 820, "y2": 440, "rot": 0}
      },
      "tags": []
    }
  }
  reference = BlockComponents.Sources.Constant(k = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 140, "y1": 320, "x2": 240, "y2": 420, "rot": 0}
      },
      "tags": []
    }
  }
  zeroorderhold = DiscreteComponents.ZeroOrderHold() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 550, "y1": 340, "x2": 650, "y2": 440, "rot": 0}
      },
      "tags": []
    }
  }
  sampler = DiscreteComponents.Sampler() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 650, "y1": 520, "x2": 550, "y2": 620, "rot": 0}
      },
      "tags": []
    }
  }
  periodicclock = DiscreteComponents.PeriodicClock(dt = 0.2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 550, "y1": 670, "x2": 650, "y2": 770, "rot": 0}
      },
      "tags": []
    }
  }
relations
  initial secondorder.x = 0.0
  initial secondorder.xd = 0.0
  connect(zeroorderhold.y, secondorder.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(secondorder.y, sampler.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 860, "y": 390}, {"x": 860, "y": 570}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(discretebinarycontroller.y, zeroorderhold.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sampler.y, discretebinarycontroller.u_m, periodicclock.y) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [], "E": -1},
        {"S": -1, "M": [{"x": 290, "y": 570}, {"x": 290, "y": 409}], "E": 2},
        {"S": 3, "M": [{"x": 470, "y": 720}], "E": -1}
      ],
      "junctions": [{"x": 470, "y": 570}],
      "renderStyle": "standard"
    }
  }
  connect(reference.y, discretebinarycontroller.u_s) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {}
end
```

## Test Cases {#Test-Cases}

No test cases defined.

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`Constant`](Examples.SimpleRelayControl.md)

  * [`DiscreteBinaryController`](Examples.SimpleRelayControl.md)

  * [`PeriodicClock`](Examples.SimpleRelayControl.md)

  * [`Sampler`](Examples.SimpleRelayControl.md)

  * [`SecondOrder`](Examples.SimpleRelayControl.md)

  * [`ZeroOrderHold`](Examples.SimpleRelayControl.md)
