Skip to content
LIBRARY
Continuous.Tests.LimPIDExternalDerivative.md

Continuous.Tests.LimPIDExternalDerivative

Test bench for the LimPIDExternalDerivative controller connected to a plant model.

Uses the same plant and step setpoint as LimPIDTest. The external derivative input is provided by a Derivative block that differentiates the plant output externally, demonstrating the intended use case where the derivative signal comes from outside the controller. A constant feedforward signal is also connected.

Usage

BlockComponents.Continuous.Tests.LimPIDExternalDerivative()

Behavior

[connect(signal+y,pid+us)connect(plant+y,pid+um)connect(pid+y,plant+u)connect(signalff+y,pid+uff)connect(plant+y,extder+u)connect(extder+y,pid+ud)connect(addp+y,proportional+u)connect(addi+y,integrator+u)connect(proportional+y,addpid+u1)connect(integrator+y,addpid+u3)connect(addpid+y,gainpid+u)connect(gainpid+y,addff+u1)connect(addff+y,limiter+u)connect(limiter+y,addsat+u1)connect(addsat+y,gaintrack+u)connect(gaintrack+y,addi+u3)connect(addff+y,addsat+u2)connect(limiter+y,y)connect(addff+u2,uff)connect(addpid+u2,ud)connect(addp+u1,us)connect(addi+u1,us)connect(addp+u2,um)connect(addi+u2,um)pid.addp.y(t)=pid.addp.k1pid.addp.u1(t)+pid.addp.k2pid.addp.u2(t)pid.addi.y(t)=pid.addi.k1pid.addi.u1(t)+pid.addi.k2pid.addi.u2(t)+pid.addi.k3pid.addi.u3(t)pid.proportional.y(t)=pid.proportional.kpid.proportional.u(t)dpid.integrator.x(t)dt=pid.integrator.kpid.integrator.u(t)pid.integrator.y(t)=pid.integrator.x(t)pid.addpid.y(t)=pid.addpid.k1pid.addpid.u1(t)+pid.addpid.k2pid.addpid.u2(t)+pid.addpid.k3pid.addpid.u3(t)pid.gainpid.y(t)=pid.gainpid.kpid.gainpid.u(t)pid.addff.y(t)=pid.addff.k1pid.addff.u1(t)+pid.addff.k2pid.addff.u2(t)pid.limiter.y(t)=clamp(pid.limiter.u(t),pid.limiter.ymin,pid.limiter.ymax)pid.addsat.y(t)=pid.addsat.k1pid.addsat.u1(t)+pid.addsat.k2pid.addsat.u2(t)pid.gaintrack.y(t)=pid.gaintrack.kpid.gaintrack.u(t)dplant.x1(t)dt=plant.x2(t)dplant.x2(t)dt=plant.u(t)plant.x1(t)0.5plant.x2(t)plant.y(t)=0.5plant.x1(t)+plant.x2(t)signal.y(t)=ifelse(tsignal.starttime,signal.height+signal.offset,signal.offset)signalff.y(t)=signalff.kdextder.x(t)dt=extder.u(t)extder.x(t)extder.Textder.y(t)=extder.k(extder.u(t)extder.x(t))extder.T]

Source

dyad
"""
Test bench for the LimPIDExternalDerivative controller connected to a plant model.

Uses the same plant and step setpoint as LimPIDTest. The external derivative input
is provided by a Derivative block that differentiates the plant output externally,
demonstrating the intended use case where the derivative signal comes from outside
the controller. A constant feedforward signal is also connected.
"""
test component LimPIDExternalDerivative
  "PID controller with external derivative input"
  pid = BlockComponents.Continuous.LimPIDExternalDerivative(Ti = 0.5, y_max = 1, y_min = -1, wp = 1, Ni = 0.9, k_ff = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 320, "y1": 43, "x2": 420, "y2": 143, "rot": 0}
      },
      "tags": []
    }
  }
  "Plant model to be controlled"
  plant = BlockComponents.Continuous.Plant() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 40, "y1": 120, "x2": 140, "y2": 220, "rot": 0}
      },
      "tags": []
    }
  }
  "Step input signal used as setpoint"
  signal = BlockComponents.Sources.Step(height = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 180, "y1": 20, "x2": 280, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Constant signal for feedforward control"
  signal_ff = BlockComponents.Sources.Constant(k = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 180, "y1": -130, "x2": 280, "y2": -30, "rot": 0}
      },
      "tags": []
    }
  }
  "External derivative block computing derivative of plant output"
  ext_der = BlockComponents.Continuous.Derivative(k = 1, T = 0.01) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 180, "y1": 230, "x2": 280, "y2": 330, "rot": 0}
      },
      "tags": []
    }
  }
relations
  initial plant.x1 = 0
  initial plant.y = 0
  connect(signal.y, pid.u_s) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(plant.y, pid.u_m) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 300, "y": 170}, {"x": 300, "y": 116}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(pid.y, plant.u) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [
            {"x": 440, "y": 94},
            {"x": 440, "y": 530},
            {"x": 20, "y": 530},
            {"x": 20, "y": 170}
          ],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(pid.u_ff, signal_ff.y) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 370, "y": -80}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(plant.y, ext_der.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 160, "y": 280}], "E": 2}],
      "junctions": [{"x": 160, "y": 170}],
      "renderStyle": "standard"
    }
  }
  connect(ext_der.y, pid.u_d) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 370, "y": 280}], "E": 2}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 10,
        "atol": {"plant.y": 0.0001, "pid.y": 0.0001},
        "expect": {"signals": ["plant.y", "pid.y"]}
      }
    }
  }
}
end
Flattened Source
dyad
"""
Test bench for the LimPIDExternalDerivative controller connected to a plant model.

Uses the same plant and step setpoint as LimPIDTest. The external derivative input
is provided by a Derivative block that differentiates the plant output externally,
demonstrating the intended use case where the derivative signal comes from outside
the controller. A constant feedforward signal is also connected.
"""
test component LimPIDExternalDerivative
  "PID controller with external derivative input"
  pid = BlockComponents.Continuous.LimPIDExternalDerivative(Ti = 0.5, y_max = 1, y_min = -1, wp = 1, Ni = 0.9, k_ff = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 320, "y1": 43, "x2": 420, "y2": 143, "rot": 0}
      },
      "tags": []
    }
  }
  "Plant model to be controlled"
  plant = BlockComponents.Continuous.Plant() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 40, "y1": 120, "x2": 140, "y2": 220, "rot": 0}
      },
      "tags": []
    }
  }
  "Step input signal used as setpoint"
  signal = BlockComponents.Sources.Step(height = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 180, "y1": 20, "x2": 280, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Constant signal for feedforward control"
  signal_ff = BlockComponents.Sources.Constant(k = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 180, "y1": -130, "x2": 280, "y2": -30, "rot": 0}
      },
      "tags": []
    }
  }
  "External derivative block computing derivative of plant output"
  ext_der = BlockComponents.Continuous.Derivative(k = 1, T = 0.01) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 180, "y1": 230, "x2": 280, "y2": 330, "rot": 0}
      },
      "tags": []
    }
  }
relations
  initial plant.x1 = 0
  initial plant.y = 0
  connect(signal.y, pid.u_s) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(plant.y, pid.u_m) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 300, "y": 170}, {"x": 300, "y": 116}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(pid.y, plant.u) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [
            {"x": 440, "y": 94},
            {"x": 440, "y": 530},
            {"x": 20, "y": 530},
            {"x": 20, "y": 170}
          ],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(pid.u_ff, signal_ff.y) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 370, "y": -80}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(plant.y, ext_der.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 160, "y": 280}], "E": 2}],
      "junctions": [{"x": 160, "y": 170}],
      "renderStyle": "standard"
    }
  }
  connect(ext_der.y, pid.u_d) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 370, "y": 280}], "E": 2}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 10,
        "atol": {"plant.y": 0.0001, "pid.y": 0.0001},
        "expect": {"signals": ["plant.y", "pid.y"]}
      }
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

julia
plt