Skip to content
LIBRARY
DiscreteBinaryController.md

DiscreteBinaryController ​

Discrete-time binary (on-off) controller with hysteresis. The controller switches between two output levels based on comparing the measurement input u_m against the u_s signal, with a hysteresis bandwidth b to prevent chattering.

The controller turns ON when the measurement drops below u_s - b/2 and stays ON until the measurement exceeds u_s + b/2, at which point it turns OFF and stays OFF until the measurement drops below u_s - b/2 again.

Connectors: ​

  • u_m: The measurement input

  • u_s: The reference signal

  • y: The control signal output

Parameters: ​

  • b: Bandwidth around reference signal within which the controller does not react

  • k: Controller gain. The output of the controller is scaled by this gain, i.e., k = 2, bool = false will result in an output of -2 or 2.

  • bool: (structural) If true (default), the controller switches between 0 and k. If false, the controller switches between -k and k.

Usage ​

DiscreteComponents.DiscreteBinaryController(b=0.1, k=1)

Parameters: ​

NameDescriptionUnitsDefault value
boolIf true, the controller switches between 0 and k. If false, the controller switches between -k and k.–true
bBandwidth around reference signal within which the controller does not react–0.1
kController gain–1

Connectors ​

  • u_m - This connector represents a real signal as an input to a component (RealInput)

  • u_s - 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
sInternal state–

Behavior ​

Source ​

dyad
"""
Discrete-time binary (on-off) controller with hysteresis. The controller switches between two output levels based on comparing the measurement input `u_m` against the `u_s` signal, with a hysteresis bandwidth `b` to prevent chattering.

The controller turns ON when the measurement drops below `u_s - b/2` and stays ON until the measurement exceeds `u_s + b/2`, at which point it turns OFF and stays OFF until the measurement drops below `u_s - b/2` again.

# Connectors:
- `u_m`: The measurement input
- `u_s`: The reference signal
- `y`: The control signal output

# Parameters:
- `b`: Bandwidth around reference signal within which the controller does not react
- `k`: Controller gain. The output of the controller is scaled by this gain, i.e., `k = 2, bool = false` will result in an output of -2 or 2.
- `bool`: (structural) If true (default), the controller switches between 0 and k. If false, the controller switches between -k and k.
"""
component DiscreteBinaryController@[input clk extends Discrete]
  "The measurement input"
  u_m = RealInput@[clk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -100, "y1": 640, "x2": 0, "y2": 740, "rot": 0}
      },
      "tags": []
    }
  }
  "The reference signal"
  u_s = RealInput@[clk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -100, "y1": 200, "x2": 0, "y2": 300, "rot": 0}
      },
      "tags": []
    }
  }
  "The control signal output"
  y = RealOutput@[clk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 1000, "y1": 450, "x2": 1100, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "If true, the controller switches between 0 and k. If false, the controller switches between -k and k."
  structural parameter bool::Boolean = true
  "Bandwidth around reference signal within which the controller does not react"
  parameter b::Real = 0.1
  "Controller gain"
  parameter k::Real = 1
  "Internal state"
  variable s::Boolean
relations
  initial s@(clk-1) = 0
  s@clk = ifelse(s@(clk-1), u_m < u_s + b / 2, u_m < u_s - b / 2)
  if bool
    y = ifelse(s, k, 0)
  else
    y = ifelse(s, k, -k)
  end
metadata {
  "Dyad": {"icons": {"default": "dyad://DiscreteComponents/BinaryController.svg"}}
}
end
Flattened Source
dyad
"""
Discrete-time binary (on-off) controller with hysteresis. The controller switches between two output levels based on comparing the measurement input `u_m` against the `u_s` signal, with a hysteresis bandwidth `b` to prevent chattering.

The controller turns ON when the measurement drops below `u_s - b/2` and stays ON until the measurement exceeds `u_s + b/2`, at which point it turns OFF and stays OFF until the measurement drops below `u_s - b/2` again.

# Connectors:
- `u_m`: The measurement input
- `u_s`: The reference signal
- `y`: The control signal output

# Parameters:
- `b`: Bandwidth around reference signal within which the controller does not react
- `k`: Controller gain. The output of the controller is scaled by this gain, i.e., `k = 2, bool = false` will result in an output of -2 or 2.
- `bool`: (structural) If true (default), the controller switches between 0 and k. If false, the controller switches between -k and k.
"""
component DiscreteBinaryController
  "The measurement input"
  u_m = RealInput@[clk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -100, "y1": 640, "x2": 0, "y2": 740, "rot": 0}
      },
      "tags": []
    }
  }
  "The reference signal"
  u_s = RealInput@[clk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -100, "y1": 200, "x2": 0, "y2": 300, "rot": 0}
      },
      "tags": []
    }
  }
  "The control signal output"
  y = RealOutput@[clk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 1000, "y1": 450, "x2": 1100, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "If true, the controller switches between 0 and k. If false, the controller switches between -k and k."
  structural parameter bool::Boolean = true
  "Bandwidth around reference signal within which the controller does not react"
  parameter b::Real = 0.1
  "Controller gain"
  parameter k::Real = 1
  "Internal state"
  variable s::Boolean
relations
  initial s@(clk-1) = 0
  s@clk = ifelse(s@(clk-1), u_m < u_s + b / 2, u_m < u_s - b / 2)
  if bool
    y = ifelse(s, k, 0)
  else
    y = ifelse(s, k, -k)
  end
metadata {
  "Dyad": {"icons": {"default": "dyad://DiscreteComponents/BinaryController.svg"}}
}
end


Test Cases ​

No test cases defined.