$(instance)RelativeSensorsTest Icon

RelativeSensorsTest

Tests for Position, Speed and Acceleration Relative Sensors

Usage

RelativeSensorsTest()

Behavior

\[ \begin{equation} \left[ \begin{array}{c} \mathrm{connect}\left( constant1_{+}y(t), force1_{+}f(t) \right) \\ \mathrm{connect}\left( constant2_{+}y(t), force2_{+}f(t) \right) \\ \mathrm{connect}\left( fixed_{+}flange, force1_{+}flange_{a}, force2_{+}flange_{a} \right) \\ \mathrm{connect}\left( force1_{+}flange_{b}, body1_{+}flange_{a} \right) \\ \mathrm{connect}\left( force2_{+}flange_{b}, body2_{+}flange_{a} \right) \\ \mathrm{connect}\left( body1_{+}flange_{b}, relative_{speed\_sensor_{+}flange\_a}, relative_{position\_sensor_{+}flange\_a}, relative_{acceleration\_sensor_{+}flange\_a} \right) \\ \mathrm{connect}\left( body2_{+}flange_{b}, relative_{speed\_sensor_{+}flange\_b}, relative_{position\_sensor_{+}flange\_b}, relative_{acceleration\_sensor_{+}flange\_b} \right) \\ \mathtt{body1.flange\_a.s}\left( t \right) = - \frac{1}{2} \mathtt{body1.L} + \mathtt{body1.s}\left( t \right) \\ \mathtt{body1.flange\_b.s}\left( t \right) = \frac{1}{2} \mathtt{body1.L} + \mathtt{body1.s}\left( t \right) \\ \mathtt{body1.v}\left( t \right) = \frac{\mathrm{d} \mathtt{body1.s}\left( t \right)}{\mathrm{d}t} \\ \mathtt{body1.a}\left( t \right) = \frac{\mathrm{d} \mathtt{body1.v}\left( t \right)}{\mathrm{d}t} \\ \left( \mathtt{body1.a}\left( t \right) + \mathtt{body1.g} \sin\left( \mathtt{body1.theta} \right) \right) \mathtt{body1.m} = \mathtt{body1.flange\_b.f}\left( t \right) + \mathtt{body1.flange\_a.f}\left( t \right) \\ \mathtt{body2.flange\_a.s}\left( t \right) = - \frac{1}{2} \mathtt{body2.L} + \mathtt{body2.s}\left( t \right) \\ \mathtt{body2.flange\_b.s}\left( t \right) = \frac{1}{2} \mathtt{body2.L} + \mathtt{body2.s}\left( t \right) \\ \mathtt{body2.v}\left( t \right) = \frac{\mathrm{d} \mathtt{body2.s}\left( t \right)}{\mathrm{d}t} \\ \mathtt{body2.a}\left( t \right) = \frac{\mathrm{d} \mathtt{body2.v}\left( t \right)}{\mathrm{d}t} \\ \left( \mathtt{body2.a}\left( t \right) + \mathtt{body2.g} \sin\left( \mathtt{body2.theta} \right) \right) \mathtt{body2.m} = \mathtt{body2.flange\_a.f}\left( t \right) + \mathtt{body2.flange\_b.f}\left( t \right) \\ \mathtt{force1.flange\_a.f}\left( t \right) = \mathtt{force1.f}\left( t \right) \\ \mathtt{force1.flange\_b.f}\left( t \right) = - \mathtt{force1.f}\left( t \right) \\ \mathtt{force2.flange\_a.f}\left( t \right) = \mathtt{force2.f}\left( t \right) \\ \mathtt{force2.flange\_b.f}\left( t \right) = - \mathtt{force2.f}\left( t \right) \\ \mathtt{fixed.flange.s}\left( t \right) = \mathtt{fixed.s0} \\ \mathtt{constant1.y}\left( t \right) = \mathtt{constant1.k} \\ \mathtt{constant2.y}\left( t \right) = \mathtt{constant2.k} \\ 0 = \mathtt{relative\_speed\_sensor.flange\_a.f}\left( t \right) + \mathtt{relative\_speed\_sensor.flange\_b.f}\left( t \right) \\ \mathtt{relative\_speed\_sensor.s\_rel}\left( t \right) = \mathtt{relative\_speed\_sensor.flange\_b.s}\left( t \right) - \mathtt{relative\_speed\_sensor.flange\_a.s}\left( t \right) \\ \mathtt{relative\_speed\_sensor.v\_rel}\left( t \right) = \frac{\mathrm{d} \mathtt{relative\_speed\_sensor.s\_rel}\left( t \right)}{\mathrm{d}t} \\ 0 = \mathtt{relative\_speed\_sensor.flange\_a.f}\left( t \right) \\ 0 = \mathtt{relative\_position\_sensor.flange\_b.f}\left( t \right) + \mathtt{relative\_position\_sensor.flange\_a.f}\left( t \right) \\ \mathtt{relative\_position\_sensor.s\_rel}\left( t \right) = \mathtt{relative\_position\_sensor.flange\_b.s}\left( t \right) - \mathtt{relative\_position\_sensor.flange\_a.s}\left( t \right) \\ 0 = \mathtt{relative\_position\_sensor.flange\_a.f}\left( t \right) \\ 0 = \mathtt{relative\_acceleration\_sensor.flange\_b.f}\left( t \right) + \mathtt{relative\_acceleration\_sensor.flange\_a.f}\left( t \right) \\ \mathtt{relative\_acceleration\_sensor.s\_rel}\left( t \right) = \mathtt{relative\_acceleration\_sensor.flange\_b.s}\left( t \right) - \mathtt{relative\_acceleration\_sensor.flange\_a.s}\left( t \right) \\ \mathtt{relative\_acceleration\_sensor.v\_rel}\left( t \right) = \frac{\mathrm{d} \mathtt{relative\_acceleration\_sensor.s\_rel}\left( t \right)}{\mathrm{d}t} \\ \mathtt{relative\_acceleration\_sensor.a\_rel}\left( t \right) = \frac{\mathrm{d} \mathtt{relative\_acceleration\_sensor.v\_rel}\left( t \right)}{\mathrm{d}t} \\ 0 = \mathtt{relative\_acceleration\_sensor.flange\_a.f}\left( t \right) \\ \end{array} \right] \end{equation} \]

Source

# Tests for Position, Speed and Acceleration Relative Sensors
test component RelativeSensorsTest
  body1 = Mass(m=1, L=0)
  body2 = Mass(m=1, L=0)
  force1 = Force()
  force2 = Force()
  fixed = Fixed()
  constant1 = BlockComponents.Constant(k=1)
  constant2 = BlockComponents.Constant(k=10)
  relative_speed_sensor = RelativeSpeedSensor()
  relative_position_sensor = RelativePositionSensor()
  relative_acceleration_sensor = RelativeAccelerationSensor()
relations
  connect(constant1.y, force1.f)
  connect(constant2.y, force2.f)
  connect(fixed.flange, force1.flange_a, force2.flange_a)
  connect(force1.flange_b, body1.flange_a)
  connect(force2.flange_b, body2.flange_a)
  connect(body1.flange_b, relative_speed_sensor.flange_a, relative_position_sensor.flange_a, relative_acceleration_sensor.flange_a)
  connect(body2.flange_b, relative_speed_sensor.flange_b, relative_position_sensor.flange_b, relative_acceleration_sensor.flange_b)
metadata {
  "JuliaSim": {
    "tests": {
      "case1": {
        "stop": 5,
        "initial": {"body1.s": 0, "body2.s": 0},
        "expect": {
          "final": {
            "relative_position_sensor.s_rel": 112.5,
            "relative_speed_sensor.v_rel": 44.99999999,
            "relative_acceleration_sensor.a_rel": 9
          }
        }
      }
    }
  }
}
end
Flattened Source
# Tests for Position, Speed and Acceleration Relative Sensors
test component RelativeSensorsTest
  body1 = Mass(m=1, L=0)
  body2 = Mass(m=1, L=0)
  force1 = Force()
  force2 = Force()
  fixed = Fixed()
  constant1 = BlockComponents.Constant(k=1)
  constant2 = BlockComponents.Constant(k=10)
  relative_speed_sensor = RelativeSpeedSensor()
  relative_position_sensor = RelativePositionSensor()
  relative_acceleration_sensor = RelativeAccelerationSensor()
relations
  connect(constant1.y, force1.f)
  connect(constant2.y, force2.f)
  connect(fixed.flange, force1.flange_a, force2.flange_a)
  connect(force1.flange_b, body1.flange_a)
  connect(force2.flange_b, body2.flange_a)
  connect(body1.flange_b, relative_speed_sensor.flange_a, relative_position_sensor.flange_a, relative_acceleration_sensor.flange_a)
  connect(body2.flange_b, relative_speed_sensor.flange_b, relative_position_sensor.flange_b, relative_acceleration_sensor.flange_b)
metadata {
  "JuliaSim": {
    "tests": {
      "case1": {
        "stop": 5,
        "initial": {"body1.s": 0, "body2.s": 0},
        "expect": {
          "final": {
            "relative_position_sensor.s_rel": 112.5,
            "relative_speed_sensor.v_rel": 44.99999999,
            "relative_acceleration_sensor.a_rel": 9
          }
        }
      }
    }
  }
}
end

Test Cases

Test Case case1