---
url: /dyad/dev/stdlib/DiscreteComponents/tests/Examples.TestDiscreteCascadeServoController.md
description: >-
  Dyad Examples.TestDiscreteCascadeServoController docs.  Position control of a
  mass with the discrete-time cascade servo controller.
---

# `Examples.TestDiscreteCascadeServoController` {#Examples.TestDiscreteCascadeServoController}

Position control of a mass with the discrete-time cascade servo controller.

The mass `m = 1` is driven by an actuator whose force follows the command with a first-order lag of time constant `0.02`. The controller samples the position, the velocity and the actuator force every `0.005` time units and moves the mass to the position reference `0.2`. With the default per-unit limits, the velocity setpoint is limited to the rated speed `v_max = 0.5`, and the ratings `f_max` and `u_max` correspond to the force range of the actuator.

## Usage {#Usage}

`DiscreteComponents.Examples.TestDiscreteCascadeServoController()`

## Behavior {#Behavior}

Behavior of this component cannot be rendered because it includes `path` variables.

## Source {#Source}

```dyad
"""
Position control of a mass with the discrete-time cascade servo controller.

The mass `m = 1` is driven by an actuator whose force follows the command with a first-order lag of time constant `0.02`. The controller samples the position, the velocity and the actuator force every `0.005` time units and moves the mass to the position reference `0.2`. With the default per-unit limits, the velocity setpoint is limited to the rated speed `v_max = 0.5`, and the ratings `f_max` and `u_max` correspond to the force range of the actuator.
"""
test component TestDiscreteCascadeServoController
  "Position reference"
  ref_s = BlockComponents.Sources.Constant(k = 0.2) {
    "Dyad": {"placement": {"diagram": {"x1": 120, "y1": 410, "x2": 200, "y2": 490}}}
  }
  "Velocity reference"
  ref_v = BlockComponents.Sources.Constant(k = 0) {
    "Dyad": {"placement": {"diagram": {"x1": 200, "y1": 160, "x2": 280, "y2": 240}}}
  }
  "Acceleration reference"
  ref_a = BlockComponents.Sources.Constant(k = 0) {
    "Dyad": {
      "placement": {"diagram": {"x1": 620, "y1": 160, "x2": 700, "y2": 240, "rot": 180}}
    }
  }
  controller = DiscreteComponents.DiscreteCascadeServoController(v_max = 0.5, f_max = 10, u_max = 10) {
    "Dyad": {"placement": {"diagram": {"x1": 300, "y1": 300, "x2": 600, "y2": 600}}}
  }
  clock = DiscreteComponents.PeriodicClock(dt = 0.005) {
    "Dyad": {"placement": {"diagram": {"x1": 60, "y1": 560, "x2": 140, "y2": 640}}}
  }
  sampler_s = DiscreteComponents.Sampler() {
    "Dyad": {
      "placement": {"diagram": {"x1": 190, "y1": 680, "x2": 270, "y2": 760, "rot": 270}}
    }
  }
  sampler_v = DiscreteComponents.Sampler() {
    "Dyad": {
      "placement": {"diagram": {"x1": 395, "y1": 680, "x2": 475, "y2": 760, "rot": 270}}
    }
  }
  sampler_f = DiscreteComponents.Sampler() {
    "Dyad": {
      "placement": {"diagram": {"x1": 580, "y1": 680, "x2": 660, "y2": 760, "rot": 270}}
    }
  }
  zoh = DiscreteComponents.ZeroOrderHold() {
    "Dyad": {
      "placement": {"diagram": {"x1": 760, "y1": 840, "x2": 840, "y2": 920, "rot": 180}}
    }
  }
  "Actuator force lag"
  actuator = BlockComponents.Continuous.FirstOrder(T = 0.02) {
    "Dyad": {
      "placement": {"diagram": {"x1": 640, "y1": 840, "x2": 720, "y2": 920, "rot": 180}}
    }
  }
  "Inverse of the mass"
  inv_mass = BlockComponents.Math.Gain(k = 1) {
    "Dyad": {
      "placement": {"diagram": {"x1": 520, "y1": 840, "x2": 600, "y2": 920, "rot": 180}}
    }
  }
  velocity = BlockComponents.Continuous.Integrator() {
    "Dyad": {
      "placement": {"diagram": {"x1": 400, "y1": 840, "x2": 480, "y2": 920, "rot": 180}}
    }
  }
  position = BlockComponents.Continuous.Integrator() {
    "Dyad": {
      "placement": {"diagram": {"x1": 280, "y1": 840, "x2": 360, "y2": 920, "rot": 180}}
    }
  }
relations
  initial actuator.x = 0
  connect(ref_s.y, controller.s_ref) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(ref_v.y, controller.v_ff) {"Dyad": {"edges": [{"S": 1, "M": [{"x": 402, "y": 200}], "E": 2}]}}
  connect(ref_a.y, controller.a_ff) {"Dyad": {"edges": [{"S": 1, "M": [{"x": 495, "y": 200}], "E": 2}]}}
  connect(controller.u, zoh.u) {
    "Dyad": {"edges": [{"S": 1, "M": [{"x": 880, "y": 450}, {"x": 880, "y": 880}], "E": 2}]}
  }
  connect(zoh.y, actuator.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(actuator.y, inv_mass.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(inv_mass.y, velocity.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(velocity.y, position.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(actuator.y, sampler_f.u) {"Dyad": {"edges": [{"S": 1, "M": [{"x": 620, "y": 880}], "E": 2}]}}
  connect(velocity.y, sampler_v.u) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 385, "y": 880}, {"x": 385, "y": 800}, {"x": 435, "y": 800}],
          "E": 2
        }
      ]
    }
  }
  connect(position.y, sampler_s.u) {"Dyad": {"edges": [{"S": 1, "M": [{"x": 230, "y": 880}], "E": 2}]}}
  connect(sampler_s.y, controller.s_meas, clock.y) {
    "Dyad": {"edges": [{"S": 1, "M": [{"x": 230, "y": 640}, {"x": 345, "y": 640}], "E": 2}]}
  }
  connect(sampler_v.y, controller.v_meas) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(sampler_f.y, controller.f_meas) {
    "Dyad": {"edges": [{"S": 1, "M": [{"x": 620, "y": 640}, {"x": 522, "y": 640}], "E": 2}]}
  }
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 3,
        "atol": {"position.y": 0.001},
        "expect": {"final": {"position.y": 0.2}}
      }
    },
    "doc": {"behavior": false}
  }
}
end
```

```dyad
"""
Position control of a mass with the discrete-time cascade servo controller.

The mass `m = 1` is driven by an actuator whose force follows the command with a first-order lag of time constant `0.02`. The controller samples the position, the velocity and the actuator force every `0.005` time units and moves the mass to the position reference `0.2`. With the default per-unit limits, the velocity setpoint is limited to the rated speed `v_max = 0.5`, and the ratings `f_max` and `u_max` correspond to the force range of the actuator.
"""
test component TestDiscreteCascadeServoController
  "Position reference"
  ref_s = BlockComponents.Sources.Constant(k = 0.2) {
    "Dyad": {"placement": {"diagram": {"x1": 120, "y1": 410, "x2": 200, "y2": 490}}}
  }
  "Velocity reference"
  ref_v = BlockComponents.Sources.Constant(k = 0) {
    "Dyad": {"placement": {"diagram": {"x1": 200, "y1": 160, "x2": 280, "y2": 240}}}
  }
  "Acceleration reference"
  ref_a = BlockComponents.Sources.Constant(k = 0) {
    "Dyad": {
      "placement": {"diagram": {"x1": 620, "y1": 160, "x2": 700, "y2": 240, "rot": 180}}
    }
  }
  controller = DiscreteComponents.DiscreteCascadeServoController(v_max = 0.5, f_max = 10, u_max = 10) {
    "Dyad": {"placement": {"diagram": {"x1": 300, "y1": 300, "x2": 600, "y2": 600}}}
  }
  clock = DiscreteComponents.PeriodicClock(dt = 0.005) {
    "Dyad": {"placement": {"diagram": {"x1": 60, "y1": 560, "x2": 140, "y2": 640}}}
  }
  sampler_s = DiscreteComponents.Sampler() {
    "Dyad": {
      "placement": {"diagram": {"x1": 190, "y1": 680, "x2": 270, "y2": 760, "rot": 270}}
    }
  }
  sampler_v = DiscreteComponents.Sampler() {
    "Dyad": {
      "placement": {"diagram": {"x1": 395, "y1": 680, "x2": 475, "y2": 760, "rot": 270}}
    }
  }
  sampler_f = DiscreteComponents.Sampler() {
    "Dyad": {
      "placement": {"diagram": {"x1": 580, "y1": 680, "x2": 660, "y2": 760, "rot": 270}}
    }
  }
  zoh = DiscreteComponents.ZeroOrderHold() {
    "Dyad": {
      "placement": {"diagram": {"x1": 760, "y1": 840, "x2": 840, "y2": 920, "rot": 180}}
    }
  }
  "Actuator force lag"
  actuator = BlockComponents.Continuous.FirstOrder(T = 0.02) {
    "Dyad": {
      "placement": {"diagram": {"x1": 640, "y1": 840, "x2": 720, "y2": 920, "rot": 180}}
    }
  }
  "Inverse of the mass"
  inv_mass = BlockComponents.Math.Gain(k = 1) {
    "Dyad": {
      "placement": {"diagram": {"x1": 520, "y1": 840, "x2": 600, "y2": 920, "rot": 180}}
    }
  }
  velocity = BlockComponents.Continuous.Integrator() {
    "Dyad": {
      "placement": {"diagram": {"x1": 400, "y1": 840, "x2": 480, "y2": 920, "rot": 180}}
    }
  }
  position = BlockComponents.Continuous.Integrator() {
    "Dyad": {
      "placement": {"diagram": {"x1": 280, "y1": 840, "x2": 360, "y2": 920, "rot": 180}}
    }
  }
relations
  initial actuator.x = 0
  connect(ref_s.y, controller.s_ref) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(ref_v.y, controller.v_ff) {"Dyad": {"edges": [{"S": 1, "M": [{"x": 402, "y": 200}], "E": 2}]}}
  connect(ref_a.y, controller.a_ff) {"Dyad": {"edges": [{"S": 1, "M": [{"x": 495, "y": 200}], "E": 2}]}}
  connect(controller.u, zoh.u) {
    "Dyad": {"edges": [{"S": 1, "M": [{"x": 880, "y": 450}, {"x": 880, "y": 880}], "E": 2}]}
  }
  connect(zoh.y, actuator.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(actuator.y, inv_mass.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(inv_mass.y, velocity.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(velocity.y, position.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(actuator.y, sampler_f.u) {"Dyad": {"edges": [{"S": 1, "M": [{"x": 620, "y": 880}], "E": 2}]}}
  connect(velocity.y, sampler_v.u) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 385, "y": 880}, {"x": 385, "y": 800}, {"x": 435, "y": 800}],
          "E": 2
        }
      ]
    }
  }
  connect(position.y, sampler_s.u) {"Dyad": {"edges": [{"S": 1, "M": [{"x": 230, "y": 880}], "E": 2}]}}
  connect(sampler_s.y, controller.s_meas, clock.y) {
    "Dyad": {"edges": [{"S": 1, "M": [{"x": 230, "y": 640}, {"x": 345, "y": 640}], "E": 2}]}
  }
  connect(sampler_v.y, controller.v_meas) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(sampler_f.y, controller.f_meas) {
    "Dyad": {"edges": [{"S": 1, "M": [{"x": 620, "y": 640}, {"x": 522, "y": 640}], "E": 2}]}
  }
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 3,
        "atol": {"position.y": 0.001},
        "expect": {"final": {"position.y": 0.2}}
      }
    },
    "doc": {"behavior": false}
  }
}
end
```

## Test Cases {#Test-Cases}

### Test Case `case1` {#Test-Case-case1}

## Related {#Related}

* Examples

* Experiments

* Analyses

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

  * [`DiscreteCascadeServoController`](Examples.TestDiscreteCascadeServoController.md)

  * [`FirstOrder`](Examples.TestDiscreteCascadeServoController.md)

  * [`Gain`](Examples.TestDiscreteCascadeServoController.md)

  * [`Integrator`](Examples.TestDiscreteCascadeServoController.md)

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

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

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