Skip to content
FeedbackTest.md

FeedbackTest

Computes the difference between two input signals.

The FeedbackTest component demonstrates a basic feedback mechanism by subtracting the value of one constant (2) from another constant (1), resulting in an output of -1. This illustrates the core functionality of a feedback control system where one signal is subtracted from another.

Usage

FeedbackTest()

Behavior

julia
using BlockComponents #hide
using ModelingToolkit #hide
@named sys = FeedbackTest() #hide
full_equations(sys) #hide
<< @example-block not executed in draft mode >>

Source

dyad
# Computes the difference between two input signals.
#
# The `FeedbackTest` component demonstrates a basic feedback mechanism by subtracting the value of
# one constant (2) from another constant (1), resulting in an output of -1. This illustrates the
# core functionality of a feedback control system where one signal is subtracted from another.
test component FeedbackTest
  # Constant block with value 1 that provides the primary input signal
  c1 = Constant(k=1)
  # Constant block with value 2 that provides the feedback signal to be subtracted
  c2 = Constant(k=2)
  # Feedback block that subtracts the second input from the first
  feedback = Feedback()
relations
  # Connects the output of constant block c1 to the primary input of the feedback block
  connect(feedback.u1, c1.y)
  # Connects the output of constant block c2 to the feedback input of the feedback block
  connect(feedback.u2, c2.y)
metadata {
  "Dyad": {"tests": {"case1": {"stop": 5, "expect": {"final": {"feedback.y": -1}}}}}
}
end
Flattened Source
dyad
# Computes the difference between two input signals.
#
# The `FeedbackTest` component demonstrates a basic feedback mechanism by subtracting the value of
# one constant (2) from another constant (1), resulting in an output of -1. This illustrates the
# core functionality of a feedback control system where one signal is subtracted from another.
test component FeedbackTest
  # Constant block with value 1 that provides the primary input signal
  c1 = Constant(k=1)
  # Constant block with value 2 that provides the feedback signal to be subtracted
  c2 = Constant(k=2)
  # Feedback block that subtracts the second input from the first
  feedback = Feedback()
relations
  # Connects the output of constant block c1 to the primary input of the feedback block
  connect(feedback.u1, c1.y)
  # Connects the output of constant block c2 to the feedback input of the feedback block
  connect(feedback.u2, c2.y)
metadata {
  "Dyad": {"tests": {"case1": {"stop": 5, "expect": {"final": {"feedback.y": -1}}}}}
}
end


Test Cases

julia
using BlockComponents
using ModelingToolkit, OrdinaryDiffEqDefault
using Plots
using CSV, DataFrames

snapshotsdir = joinpath(dirname(dirname(pathof(BlockComponents))), "test", "snapshots")
<< @setup-block not executed in draft mode >>

Test Case case1

julia
@mtkbuild model_case1 = FeedbackTest()
u0_case1 = []
prob_case1 = ODEProblem(model_case1, u0_case1, (0, 5))
sol_case1 = solve(prob_case1)
<< @setup-block not executed in draft mode >>