Skip to content
LIBRARY
Examples.LinearMPCExportExample.md

Examples.LinearMPCExportExample ​

A LinearMPCController for the double integrator with its clock and free top-level connectors: the shape a controller takes to be exported as standalone C (see CCodeExport and LinearMPCExportDemo). y is the sampled position, r the position reference, u the control and status the solver's exit flag; the PeriodicClock connected to y sets the sample time of the whole controller.

Usage ​

MPCComponents.Examples.LinearMPCExportExample()

Connectors ​

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

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

  • u - This connector represents a real signal as an output from a component (RealOutput)

  • status - This connector represents a real signal as an output from a component (RealOutput)

Behavior ​

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

Source ​

dyad
"""
A `LinearMPCController` for the double integrator with its clock and free top-level connectors:
the shape a controller takes to be exported as standalone C (see `CCodeExport` and
`LinearMPCExportDemo`). `y` is the sampled position, `r` the position reference, `u` the
control and `status` the solver's exit flag; the `PeriodicClock` connected to `y` sets the sample
time of the whole controller.
"""
example component LinearMPCExportExample
  "Sampled position measurement"
  y = RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -100, "y1": 350, "x2": 0, "y2": 450, "rot": 0}
      },
      "tags": []
    }
  }
  "Position reference"
  r = RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -100, "y1": 550, "x2": 0, "y2": 650, "rot": 0}
      },
      "tags": []
    }
  }
  "Control signal"
  u = RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 1000, "y1": 450, "x2": 1100, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Solver status (DAQP exit flag)"
  status = RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 1000, "y1": 650, "x2": 1100, "y2": 750, "rot": 0}
      },
      "tags": []
    }
  }
  periodicclock = DiscreteComponents.PeriodicClock(dt = 0.1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 200, "y1": 700, "x2": 400, "y2": 900, "rot": 0}
      },
      "tags": []
    }
  }
  mpc = MPCComponents.LinearMPCController(A = [[1.0, 0.1], [0.0, 1.0]], B = [[0.005], [0.1]], C = [[1.0, 0.0]], Q1 = [1.0], Q2 = [0.1], Q3 = [0.05], umin = [-1.0], umax = [1.0], Np = 10, R1 = [0.01, 0.01], R2 = [0.1]) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 400, "y1": 350, "x2": 600, "y2": 650, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(y, mpc.y[1], periodicclock.y) {}
  connect(r, mpc.r[1]) {}
  connect(mpc.u[1], u) {}
  connect(mpc.exitflag, status) {}
metadata {"Dyad": {"doc": {"behavior": false}}}
end
Flattened Source
dyad
"""
A `LinearMPCController` for the double integrator with its clock and free top-level connectors:
the shape a controller takes to be exported as standalone C (see `CCodeExport` and
`LinearMPCExportDemo`). `y` is the sampled position, `r` the position reference, `u` the
control and `status` the solver's exit flag; the `PeriodicClock` connected to `y` sets the sample
time of the whole controller.
"""
example component LinearMPCExportExample
  "Sampled position measurement"
  y = RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -100, "y1": 350, "x2": 0, "y2": 450, "rot": 0}
      },
      "tags": []
    }
  }
  "Position reference"
  r = RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -100, "y1": 550, "x2": 0, "y2": 650, "rot": 0}
      },
      "tags": []
    }
  }
  "Control signal"
  u = RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 1000, "y1": 450, "x2": 1100, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Solver status (DAQP exit flag)"
  status = RealOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 1000, "y1": 650, "x2": 1100, "y2": 750, "rot": 0}
      },
      "tags": []
    }
  }
  periodicclock = DiscreteComponents.PeriodicClock(dt = 0.1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 200, "y1": 700, "x2": 400, "y2": 900, "rot": 0}
      },
      "tags": []
    }
  }
  mpc = MPCComponents.LinearMPCController(A = [[1.0, 0.1], [0.0, 1.0]], B = [[0.005], [0.1]], C = [[1.0, 0.0]], Q1 = [1.0], Q2 = [0.1], Q3 = [0.05], umin = [-1.0], umax = [1.0], Np = 10, R1 = [0.01, 0.01], R2 = [0.1]) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 400, "y1": 350, "x2": 600, "y2": 650, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(y, mpc.y[1], periodicclock.y) {}
  connect(r, mpc.r[1]) {}
  connect(mpc.u[1], u) {}
  connect(mpc.exitflag, status) {}
metadata {"Dyad": {"doc": {"behavior": false}}}
end


Test Cases ​

No test cases defined.

  • Examples

  • Experiments

  • Analyses