---
url: /dyad/dev/stdlib/DiscreteComponents/tests/Examples.TestDiscreteCascadeServoControllerFF.md
description: >-
  Dyad Examples.TestDiscreteCascadeServoControllerFF docs.  Position control of
  a mass with the discrete-time cascade servo controller, with acceleration
  feedforward and nondefault settings.
---

# `Examples.TestDiscreteCascadeServoControllerFF` {#Examples.TestDiscreteCascadeServoControllerFF}

Position control of a mass with the discrete-time cascade servo controller, with acceleration feedforward and nondefault settings.

The plant is the same as in `TestDiscreteCascadeServoController`. The velocity feedforward input is removed (`with_v_ff = false`), and the constant acceleration reference `0.4` is fed forward with `ka_ff = 0.5`. The integrators use backward-Euler discretization, the anti-windup ratio is `Ni = 0.5`, the force loop is initialized such that its first unsaturated output is `1`, the velocity setpoint is limited asymmetrically to the per-unit range `[-0.4, 0.6]` of `v_max = 0.5`, and the command is limited to the per-unit range `[-0.15, 0.15]` of `u_max = 10`, so that the anti-windup of the force loop becomes active.

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.TestDiscreteCascadeServoControllerFF()`

## 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, with acceleration feedforward and nondefault settings.

The plant is the same as in `TestDiscreteCascadeServoController`. The velocity feedforward input is removed (`with_v_ff = false`), and the constant acceleration reference `0.4` is fed forward with `ka_ff = 0.5`. The integrators use backward-Euler discretization, the anti-windup ratio is `Ni = 0.5`, the force loop is initialized such that its first unsaturated output is `1`, the velocity setpoint is limited asymmetrically to the per-unit range `[-0.4, 0.6]` of `v_max = 0.5`, and the command is limited to the per-unit range `[-0.15, 0.15]` of `u_max = 10`, so that the anti-windup of the force loop becomes active.

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 TestDiscreteCascadeServoControllerFF
  "Position reference"
  ref_s = BlockComponents.Sources.Constant(k = 0.2) {
    "Dyad": {"placement": {"diagram": {"x1": 120, "y1": 410, "x2": 200, "y2": 490}}}
  }
  "Acceleration reference"
  ref_a = BlockComponents.Sources.Constant(k = 0.4) {
    "Dyad": {
      "placement": {"diagram": {"x1": 620, "y1": 160, "x2": 700, "y2": 240, "rot": 180}}
    }
  }
  controller = DiscreteComponents.DiscreteCascadeServoController(with_v_ff = false, Imethod = DiscretizationMethod.Backward(), initialization_force = DiscreteComponents.InitialCondition.InitialOutput(y0 = 1.0), ka_ff = 0.5, Ni = 0.5, v_max = 0.5, v_lim_max = 0.6, v_lim_min = -0.4, f_max = 10, u_max = 10, u_lim_max = 0.15) {
    "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_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": 4,
        "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, with acceleration feedforward and nondefault settings.

The plant is the same as in `TestDiscreteCascadeServoController`. The velocity feedforward input is removed (`with_v_ff = false`), and the constant acceleration reference `0.4` is fed forward with `ka_ff = 0.5`. The integrators use backward-Euler discretization, the anti-windup ratio is `Ni = 0.5`, the force loop is initialized such that its first unsaturated output is `1`, the velocity setpoint is limited asymmetrically to the per-unit range `[-0.4, 0.6]` of `v_max = 0.5`, and the command is limited to the per-unit range `[-0.15, 0.15]` of `u_max = 10`, so that the anti-windup of the force loop becomes active.

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 TestDiscreteCascadeServoControllerFF
  "Position reference"
  ref_s = BlockComponents.Sources.Constant(k = 0.2) {
    "Dyad": {"placement": {"diagram": {"x1": 120, "y1": 410, "x2": 200, "y2": 490}}}
  }
  "Acceleration reference"
  ref_a = BlockComponents.Sources.Constant(k = 0.4) {
    "Dyad": {
      "placement": {"diagram": {"x1": 620, "y1": 160, "x2": 700, "y2": 240, "rot": 180}}
    }
  }
  controller = DiscreteComponents.DiscreteCascadeServoController(with_v_ff = false, Imethod = DiscretizationMethod.Backward(), initialization_force = DiscreteComponents.InitialCondition.InitialOutput(y0 = 1.0), ka_ff = 0.5, Ni = 0.5, v_max = 0.5, v_lim_max = 0.6, v_lim_min = -0.4, f_max = 10, u_max = 10, u_lim_max = 0.15) {
    "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_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": 4,
        "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.TestDiscreteCascadeServoControllerFF.md)

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

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

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

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

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

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

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