---
url: /dyad/stable/stdlib/TranslationalComponents/tests/Sensors.Tests.RelativeSensors.md
description: >-
  Dyad Sensors.Tests.RelativeSensors docs.  A test rig for sensors measuring
  relative translational motion between two independently forced masses.
---

# `Sensors.Tests.RelativeSensors` {#Sensors.Tests.RelativeSensors}

A test rig for sensors measuring relative translational motion between two independently forced masses.

This test component sets up a dynamic system to verify the behavior of relative motion sensors. It features two 1kg masses, `body1` and `body2`, initially at rest and starting from the same position. `body1` is subjected to a constant force `F_1 = 1\,\text{N}` and `body2` is subjected to a constant force `F_2 = 10\,\text{N}`. Both forces are applied with respect to a fixed inertial frame. Consequently, `body1` experiences a constant acceleration `math a_1 = F_1/m_1 = 1\,\text{m/s}^2` and `body2` experiences a constant acceleration `math a_2 = F_2/m_2 = 10\,\text{m/s}^2`. Three types of sensors measure the relative motion, defined as the motion of `body2` with respect to `body1`:

* Relative position: `math s_{rel}(t) = s_2(t) - s_1(t)`

* Relative speed: `math v_{rel}(t) = v_2(t) - v_1(t) = \frac{d}{dt}s_{rel}(t)`

* Relative acceleration: `math a_{rel}(t) = a_2(t) - a_1(t) = \frac{d}{dt}v_{rel}(t)`

## Usage {#Usage}

`TranslationalComponents.Sensors.Tests.RelativeSensors()`

## Behavior {#Behavior}

## Source {#Source}

````dyad
"""
A test rig for sensors measuring relative translational motion between two independently forced masses.

This test component sets up a dynamic system to verify the behavior of relative motion sensors. It features two 1kg masses, `body1` and `body2`, initially at rest and starting from the same position.
`body1` is subjected to a constant force `F_1 = 1\,\text{N}` and `body2` is subjected to a constant force `F_2 = 10\,\text{N}`. Both forces are applied with respect to a fixed inertial frame.
Consequently, `body1` experiences a constant acceleration ```math a_1 = F_1/m_1 = 1\,\text{m/s}^2 ``` and `body2` experiences a constant acceleration ```math a_2 = F_2/m_2 = 10\,\text{m/s}^2 ```.
Three types of sensors measure the relative motion, defined as the motion of `body2` with respect to `body1`:
- Relative position: ```math s_{rel}(t) = s_2(t) - s_1(t) ```
- Relative speed: ```math v_{rel}(t) = v_2(t) - v_1(t) = \frac{d}{dt}s_{rel}(t) ```
- Relative acceleration: ```math a_{rel}(t) = a_2(t) - a_1(t) = \frac{d}{dt}v_{rel}(t) ```
"""
test component RelativeSensors
  "First translational mass (1kg) in the test setup."
  body1 = TranslationalComponents.Components.Mass(m = 1, L = 0) {
    "Dyad": {"placement": {"diagram": {"x1": 415, "x2": 515, "y1": 250, "y2": 350}}}
  }
  "Second translational mass (1kg) in the test setup."
  body2 = TranslationalComponents.Components.Mass(m = 1, L = 0) {
    "Dyad": {"placement": {"diagram": {"x1": 415, "x2": 515, "y1": 130, "y2": 230}}}
  }
  "Force source applying force to body1."
  force1 = TranslationalComponents.Sources.Force() {
    "Dyad": {"placement": {"diagram": {"x1": 155, "x2": 255, "y1": 250, "y2": 350}}}
  }
  "Force source applying force to body2."
  force2 = TranslationalComponents.Sources.Force() {
    "Dyad": {"placement": {"diagram": {"x1": 285, "x2": 385, "y1": 130, "y2": 230}}}
  }
  "Fixed inertial reference frame for the applied forces."
  fixed = TranslationalComponents.Components.Fixed() {
    "Dyad": {"placement": {"diagram": {"x1": 25, "x2": 125, "y1": 355, "y2": 455}}}
  }
  "Constant signal (1.0, typically Force [N]) for force1."
  constant1 = BlockComponents.Sources.Constant(k = 1) {
    "Dyad": {"placement": {"diagram": {"x1": 20, "x2": 120, "y1": 120, "y2": 220}}}
  }
  "Constant signal (10.0, typically Force [N]) for force2."
  constant2 = BlockComponents.Sources.Constant(k = 10) {
    "Dyad": {"placement": {"diagram": {"x1": 150, "x2": 250, "y1": 10, "y2": 110}}}
  }
  "Sensor measuring the relative speed between body1 and body2 (v_body2 - v_body1)."
  relative_speed_sensor = TranslationalComponents.Sensors.RelativeVelocitySensor() {
    "Dyad": {"placement": {"diagram": {"x1": 545, "x2": 645, "y1": 250, "y2": 350}}}
  }
  "Sensor measuring the relative position between body1 and body2 (s_body2 - s_body1)."
  relative_position_sensor = TranslationalComponents.Sensors.RelativePositionSensor() {
    "Dyad": {"placement": {"diagram": {"x1": 675, "x2": 775, "y1": 325, "y2": 425}}}
  }
  "Sensor measuring the relative acceleration between body1 and body2 (a_body2 - a_body1)."
  relative_acceleration_sensor = TranslationalComponents.Sensors.RelativeAccelerationSensor() {
    "Dyad": {"placement": {"diagram": {"x1": 805, "x2": 905, "y1": 430, "y2": 530}}}
  }
relations
  connect(constant1.y, force1.f) {"Dyad": {"edges": [{"S": 1, "M": [{"x": 205, "y": 170}], "E": 2}]}}
  connect(constant2.y, force2.f) {"Dyad": {"edges": [{"S": 1, "M": [{"x": 335, "y": 60}], "E": 2}]}}
  connect(fixed.flange, force1.flange_a, force2.flange_a) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 75, "y": 300}], "E": -1},
        {"S": -1, "M": [], "E": 2},
        {"S": -1, "M": [{"x": 140, "y": 180}], "E": 3}
      ],
      "junctions": [{"x": 140, "y": 300}]
    }
  }
  connect(force1.flange_b, body1.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(force2.flange_b, body2.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(body1.flange_b, relative_speed_sensor.flange_a, relative_position_sensor.flange_a, relative_acceleration_sensor.flange_a) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [], "E": -1},
        {"S": -1, "M": [], "E": 2},
        {"S": -1, "M": [{"x": 530, "y": 375}], "E": -2},
        {"S": -2, "M": [], "E": 3},
        {"S": -2, "M": [{"x": 660, "y": 480}], "E": 4}
      ],
      "junctions": [{"x": 530, "y": 300}, {"x": 660, "y": 375}]
    }
  }
  connect(body2.flange_b, relative_speed_sensor.flange_b, relative_position_sensor.flange_b, relative_acceleration_sensor.flange_b) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 660, "y": 180}], "E": -1},
        {"S": -1, "M": [], "E": 2},
        {"S": -1, "M": [{"x": 790, "y": 300}], "E": -2},
        {"S": -2, "M": [], "E": 3},
        {"S": -2, "M": [{"x": 920, "y": 375}, {"x": 920, "y": 480}], "E": 4}
      ],
      "junctions": [{"x": 660, "y": 300}, {"x": 790, "y": 375}]
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://TranslationalComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 5,
        "initial": {"body1.s": 0, "body2.s": 0, "body1.v": 0, "body2.v": 0},
        "atol": {
          "relative_position_sensor.s_rel": 0.01,
          "relative_speed_sensor.v_rel": 0.01,
          "relative_acceleration_sensor.a_rel": 0.01
        },
        "expect": {
          "final": {
            "relative_position_sensor.s_rel": 112.5,
            "relative_speed_sensor.v_rel": 44.99999999,
            "relative_acceleration_sensor.a_rel": 9
          },
          "signals": [
            "relative_position_sensor.s_rel",
            "relative_speed_sensor.v_rel",
            "relative_acceleration_sensor.a_rel"
          ]
        }
      }
    }
  }
}
end
````

````dyad
"""
A test rig for sensors measuring relative translational motion between two independently forced masses.

This test component sets up a dynamic system to verify the behavior of relative motion sensors. It features two 1kg masses, `body1` and `body2`, initially at rest and starting from the same position.
`body1` is subjected to a constant force `F_1 = 1\,\text{N}` and `body2` is subjected to a constant force `F_2 = 10\,\text{N}`. Both forces are applied with respect to a fixed inertial frame.
Consequently, `body1` experiences a constant acceleration ```math a_1 = F_1/m_1 = 1\,\text{m/s}^2 ``` and `body2` experiences a constant acceleration ```math a_2 = F_2/m_2 = 10\,\text{m/s}^2 ```.
Three types of sensors measure the relative motion, defined as the motion of `body2` with respect to `body1`:
- Relative position: ```math s_{rel}(t) = s_2(t) - s_1(t) ```
- Relative speed: ```math v_{rel}(t) = v_2(t) - v_1(t) = \frac{d}{dt}s_{rel}(t) ```
- Relative acceleration: ```math a_{rel}(t) = a_2(t) - a_1(t) = \frac{d}{dt}v_{rel}(t) ```
"""
test component RelativeSensors
  "First translational mass (1kg) in the test setup."
  body1 = TranslationalComponents.Components.Mass(m = 1, L = 0) {
    "Dyad": {"placement": {"diagram": {"x1": 415, "x2": 515, "y1": 250, "y2": 350}}}
  }
  "Second translational mass (1kg) in the test setup."
  body2 = TranslationalComponents.Components.Mass(m = 1, L = 0) {
    "Dyad": {"placement": {"diagram": {"x1": 415, "x2": 515, "y1": 130, "y2": 230}}}
  }
  "Force source applying force to body1."
  force1 = TranslationalComponents.Sources.Force() {
    "Dyad": {"placement": {"diagram": {"x1": 155, "x2": 255, "y1": 250, "y2": 350}}}
  }
  "Force source applying force to body2."
  force2 = TranslationalComponents.Sources.Force() {
    "Dyad": {"placement": {"diagram": {"x1": 285, "x2": 385, "y1": 130, "y2": 230}}}
  }
  "Fixed inertial reference frame for the applied forces."
  fixed = TranslationalComponents.Components.Fixed() {
    "Dyad": {"placement": {"diagram": {"x1": 25, "x2": 125, "y1": 355, "y2": 455}}}
  }
  "Constant signal (1.0, typically Force [N]) for force1."
  constant1 = BlockComponents.Sources.Constant(k = 1) {
    "Dyad": {"placement": {"diagram": {"x1": 20, "x2": 120, "y1": 120, "y2": 220}}}
  }
  "Constant signal (10.0, typically Force [N]) for force2."
  constant2 = BlockComponents.Sources.Constant(k = 10) {
    "Dyad": {"placement": {"diagram": {"x1": 150, "x2": 250, "y1": 10, "y2": 110}}}
  }
  "Sensor measuring the relative speed between body1 and body2 (v_body2 - v_body1)."
  relative_speed_sensor = TranslationalComponents.Sensors.RelativeVelocitySensor() {
    "Dyad": {"placement": {"diagram": {"x1": 545, "x2": 645, "y1": 250, "y2": 350}}}
  }
  "Sensor measuring the relative position between body1 and body2 (s_body2 - s_body1)."
  relative_position_sensor = TranslationalComponents.Sensors.RelativePositionSensor() {
    "Dyad": {"placement": {"diagram": {"x1": 675, "x2": 775, "y1": 325, "y2": 425}}}
  }
  "Sensor measuring the relative acceleration between body1 and body2 (a_body2 - a_body1)."
  relative_acceleration_sensor = TranslationalComponents.Sensors.RelativeAccelerationSensor() {
    "Dyad": {"placement": {"diagram": {"x1": 805, "x2": 905, "y1": 430, "y2": 530}}}
  }
relations
  connect(constant1.y, force1.f) {"Dyad": {"edges": [{"S": 1, "M": [{"x": 205, "y": 170}], "E": 2}]}}
  connect(constant2.y, force2.f) {"Dyad": {"edges": [{"S": 1, "M": [{"x": 335, "y": 60}], "E": 2}]}}
  connect(fixed.flange, force1.flange_a, force2.flange_a) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 75, "y": 300}], "E": -1},
        {"S": -1, "M": [], "E": 2},
        {"S": -1, "M": [{"x": 140, "y": 180}], "E": 3}
      ],
      "junctions": [{"x": 140, "y": 300}]
    }
  }
  connect(force1.flange_b, body1.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(force2.flange_b, body2.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
  connect(body1.flange_b, relative_speed_sensor.flange_a, relative_position_sensor.flange_a, relative_acceleration_sensor.flange_a) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [], "E": -1},
        {"S": -1, "M": [], "E": 2},
        {"S": -1, "M": [{"x": 530, "y": 375}], "E": -2},
        {"S": -2, "M": [], "E": 3},
        {"S": -2, "M": [{"x": 660, "y": 480}], "E": 4}
      ],
      "junctions": [{"x": 530, "y": 300}, {"x": 660, "y": 375}]
    }
  }
  connect(body2.flange_b, relative_speed_sensor.flange_b, relative_position_sensor.flange_b, relative_acceleration_sensor.flange_b) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 660, "y": 180}], "E": -1},
        {"S": -1, "M": [], "E": 2},
        {"S": -1, "M": [{"x": 790, "y": 300}], "E": -2},
        {"S": -2, "M": [], "E": 3},
        {"S": -2, "M": [{"x": 920, "y": 375}, {"x": 920, "y": 480}], "E": 4}
      ],
      "junctions": [{"x": 660, "y": 300}, {"x": 790, "y": 375}]
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://TranslationalComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 5,
        "initial": {"body1.s": 0, "body2.s": 0, "body1.v": 0, "body2.v": 0},
        "atol": {
          "relative_position_sensor.s_rel": 0.01,
          "relative_speed_sensor.v_rel": 0.01,
          "relative_acceleration_sensor.a_rel": 0.01
        },
        "expect": {
          "final": {
            "relative_position_sensor.s_rel": 112.5,
            "relative_speed_sensor.v_rel": 44.99999999,
            "relative_acceleration_sensor.a_rel": 9
          },
          "signals": [
            "relative_position_sensor.s_rel",
            "relative_speed_sensor.v_rel",
            "relative_acceleration_sensor.a_rel"
          ]
        }
      }
    }
  }
}
end
````

## Test Cases {#Test-Cases}

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

```julia
plt
```

![](bsrmvkt.svg)

```julia
plt
```

![](mjolkns.svg)

```julia
plt
```

![](aaywpxa.svg)

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`Constant`](Sensors.Tests.RelativeSensors.md)

  * [`Fixed`](Sensors.Tests.RelativeSensors.md)

  * [`Force`](Sensors.Tests.RelativeSensors.md)

  * [`Mass`](Sensors.Tests.RelativeSensors.md)

  * [`RelativeAccelerationSensor`](Sensors.Tests.RelativeSensors.md)

  * [`RelativePositionSensor`](Sensors.Tests.RelativeSensors.md)

  * [`RelativeVelocitySensor`](Sensors.Tests.RelativeSensors.md)
