Skip to content
LIBRARY
Examples.Sensors.md

Examples.Sensors ​

Demonstrate sensors for translational systems.

Replicates the structure of Modelica.Mechanics.Translational.Examples.Sensors.

A sinusoidal force drives a mass. Various sensors measure the system response: force, position, speed, acceleration, and multi-sensor (combined).

Note: MSL uses a one-flange Force source with ForceSensor in series. Here we use the two-flange Force with flange_b connected to a Fixed ground. The ForceSensor is placed between the Force source and the mass.

Usage ​

TranslationalComponents.Examples.Sensors()

Behavior ​

Source ​

dyad
"""
Demonstrate sensors for translational systems.

Replicates the structure of Modelica.Mechanics.Translational.Examples.Sensors.

A sinusoidal force drives a mass. Various sensors measure the system response:
force, position, speed, acceleration, and multi-sensor (combined).

Note: MSL uses a one-flange Force source with ForceSensor in series. Here we
use the two-flange Force with flange_b connected to a Fixed ground.
The ForceSensor is placed between the Force source and the mass.
"""
example component Sensors
  "Sinusoidal force signal"
  sine_force = BlockComponents.Sources.Sine(amplitude = 10, frequency = 4) {"Dyad": {"placement": {"diagram": {"x1": 20, "x2": 120, "y1": 30, "y2": 130}}}}
  "Force source"
  force = TranslationalComponents.Sources.Force() {
    "Dyad": {"placement": {"diagram": {"x1": 155, "x2": 255, "y1": 140, "y2": 240}}}
  }
  "Ground for force source"
  force_ground = TranslationalComponents.Components.Fixed() {
    "Dyad": {"placement": {"diagram": {"x1": 285, "x2": 385, "y1": 350, "y2": 450}}}
  }
  "Force sensor"
  force_sensor = TranslationalComponents.Sensors.ForceSensor() {
    "Dyad": {"placement": {"diagram": {"x1": 285, "x2": 385, "y1": 140, "y2": 240}}}
  }
  "Multi-sensor (force, position, speed, acceleration, power)"
  multi_sensor = TranslationalComponents.Sensors.MultiSensor() {
    "Dyad": {"placement": {"diagram": {"x1": 415, "x2": 515, "y1": 140, "y2": 240}}}
  }
  "Mass"
  mass = TranslationalComponents.Components.Mass(L = 1, m = 1, s(initial = 0), v(initial = 0)) {
    "Dyad": {"placement": {"diagram": {"x1": 545, "x2": 645, "y1": 140, "y2": 240}}}
  }
  "Position sensor at flange_a"
  position_sensor1 = TranslationalComponents.Sensors.PositionSensor() {
    "Dyad": {"placement": {"diagram": {"x1": 680, "x2": 780, "y1": 20, "y2": 120}}}
  }
  "Speed sensor"
  speed_sensor1 = TranslationalComponents.Sensors.VelocitySensor() {
    "Dyad": {"placement": {"diagram": {"x1": 675, "x2": 775, "y1": 260, "y2": 360}}}
  }
  "Acceleration sensor"
  acc_sensor1 = TranslationalComponents.Sensors.AccelerationSensor() {
    "Dyad": {"placement": {"diagram": {"x1": 675, "x2": 775, "y1": 380, "y2": 480}}}
  }
  "Position sensor at flange_b"
  position_sensor2 = TranslationalComponents.Sensors.PositionSensor() {
    "Dyad": {"placement": {"diagram": {"x1": 675, "x2": 775, "y1": 140, "y2": 240}}}
  }
relations
  connect(sine_force.y, force.f) {"Dyad": {"edges": [{"S": 1, "M": [{"x": 205, "y": 80}], "E": 2}]}}
  connect(force.flange_a, force_ground.flange) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 140, "y": 190}, {"x": 140, "y": 295}, {"x": 335, "y": 295}],
          "E": 2
        }
      ]
    }
  }
  connect(force.flange_b, force_sensor.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(force_sensor.flange_b, multi_sensor.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(multi_sensor.flange_b, mass.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(mass.flange_a, position_sensor1.flange) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 530, "y": 70}], "E": 2}],
      "junctions": [{"x": 530, "y": 190}]
    }
  }
  connect(mass.flange_a, speed_sensor1.flange) {
    "Dyad": {"edges": [{"S": 1, "M": [{"x": 530, "y": 190}, {"x": 530, "y": 310}], "E": 2}]}
  }
  connect(mass.flange_a, acc_sensor1.flange) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 530, "y": 190}, {"x": 530, "y": 310}], "E": -1},
        {"S": -1, "M": [{"x": 660, "y": 430}], "E": 2}
      ],
      "junctions": [{"x": 660, "y": 310}]
    }
  }
  connect(mass.flange_b, position_sensor2.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://TranslationalComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1,
        "atol": {
          "mass.s": 0.001,
          "mass.v": 0.001,
          "speed_sensor1.v": 0.001,
          "acc_sensor1.a": 0.01
        },
        "expect": {
          "final": {"mass.s": 0.3978874, "mass.v": 0, "speed_sensor1.v": 0, "acc_sensor1.a": 0},
          "signals": ["mass.s", "mass.v", "speed_sensor1.v", "acc_sensor1.a"]
        }
      }
    }
  }
}
end
Flattened Source
dyad
"""
Demonstrate sensors for translational systems.

Replicates the structure of Modelica.Mechanics.Translational.Examples.Sensors.

A sinusoidal force drives a mass. Various sensors measure the system response:
force, position, speed, acceleration, and multi-sensor (combined).

Note: MSL uses a one-flange Force source with ForceSensor in series. Here we
use the two-flange Force with flange_b connected to a Fixed ground.
The ForceSensor is placed between the Force source and the mass.
"""
example component Sensors
  "Sinusoidal force signal"
  sine_force = BlockComponents.Sources.Sine(amplitude = 10, frequency = 4) {"Dyad": {"placement": {"diagram": {"x1": 20, "x2": 120, "y1": 30, "y2": 130}}}}
  "Force source"
  force = TranslationalComponents.Sources.Force() {
    "Dyad": {"placement": {"diagram": {"x1": 155, "x2": 255, "y1": 140, "y2": 240}}}
  }
  "Ground for force source"
  force_ground = TranslationalComponents.Components.Fixed() {
    "Dyad": {"placement": {"diagram": {"x1": 285, "x2": 385, "y1": 350, "y2": 450}}}
  }
  "Force sensor"
  force_sensor = TranslationalComponents.Sensors.ForceSensor() {
    "Dyad": {"placement": {"diagram": {"x1": 285, "x2": 385, "y1": 140, "y2": 240}}}
  }
  "Multi-sensor (force, position, speed, acceleration, power)"
  multi_sensor = TranslationalComponents.Sensors.MultiSensor() {
    "Dyad": {"placement": {"diagram": {"x1": 415, "x2": 515, "y1": 140, "y2": 240}}}
  }
  "Mass"
  mass = TranslationalComponents.Components.Mass(L = 1, m = 1, s(initial = 0), v(initial = 0)) {
    "Dyad": {"placement": {"diagram": {"x1": 545, "x2": 645, "y1": 140, "y2": 240}}}
  }
  "Position sensor at flange_a"
  position_sensor1 = TranslationalComponents.Sensors.PositionSensor() {
    "Dyad": {"placement": {"diagram": {"x1": 680, "x2": 780, "y1": 20, "y2": 120}}}
  }
  "Speed sensor"
  speed_sensor1 = TranslationalComponents.Sensors.VelocitySensor() {
    "Dyad": {"placement": {"diagram": {"x1": 675, "x2": 775, "y1": 260, "y2": 360}}}
  }
  "Acceleration sensor"
  acc_sensor1 = TranslationalComponents.Sensors.AccelerationSensor() {
    "Dyad": {"placement": {"diagram": {"x1": 675, "x2": 775, "y1": 380, "y2": 480}}}
  }
  "Position sensor at flange_b"
  position_sensor2 = TranslationalComponents.Sensors.PositionSensor() {
    "Dyad": {"placement": {"diagram": {"x1": 675, "x2": 775, "y1": 140, "y2": 240}}}
  }
relations
  connect(sine_force.y, force.f) {"Dyad": {"edges": [{"S": 1, "M": [{"x": 205, "y": 80}], "E": 2}]}}
  connect(force.flange_a, force_ground.flange) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 140, "y": 190}, {"x": 140, "y": 295}, {"x": 335, "y": 295}],
          "E": 2
        }
      ]
    }
  }
  connect(force.flange_b, force_sensor.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(force_sensor.flange_b, multi_sensor.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(multi_sensor.flange_b, mass.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(mass.flange_a, position_sensor1.flange) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 530, "y": 70}], "E": 2}],
      "junctions": [{"x": 530, "y": 190}]
    }
  }
  connect(mass.flange_a, speed_sensor1.flange) {
    "Dyad": {"edges": [{"S": 1, "M": [{"x": 530, "y": 190}, {"x": 530, "y": 310}], "E": 2}]}
  }
  connect(mass.flange_a, acc_sensor1.flange) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 530, "y": 190}, {"x": 530, "y": 310}], "E": -1},
        {"S": -1, "M": [{"x": 660, "y": 430}], "E": 2}
      ],
      "junctions": [{"x": 660, "y": 310}]
    }
  }
  connect(mass.flange_b, position_sensor2.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://TranslationalComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1,
        "atol": {
          "mass.s": 0.001,
          "mass.v": 0.001,
          "speed_sensor1.v": 0.001,
          "acc_sensor1.a": 0.01
        },
        "expect": {
          "final": {"mass.s": 0.3978874, "mass.v": 0, "speed_sensor1.v": 0, "acc_sensor1.a": 0},
          "signals": ["mass.s", "mass.v", "speed_sensor1.v", "acc_sensor1.a"]
        }
      }
    }
  }
}
end


Test Cases ​

Test Case case1 ​

julia
plt

julia
plt

julia
plt

julia
plt