Sensors.Tests.Sensors
Test environment for verifying absolute position, speed, and acceleration sensors monitoring a mass driven by a constant force.
This test component simulates a one-dimensional translational mechanical system to validate the behavior of absolute sensors. A mass (body) is subjected to a constant force (force, driven by constant1). One side of the force element is connected to a fixed point (ground), and the other side acts on the mass. The sensors (position_sensor, speed_sensor, acceleration_sensor) are then attached to this mass to measure its absolute position, speed, and acceleration, respectively. The metadata section includes a test case that checks if the sensor outputs match these expected dynamics.
Usage
TranslationalComponents.Sensors.Tests.Sensors()
Behavior
Source
"""
Test environment for verifying absolute position, speed, and acceleration sensors monitoring a mass driven by a constant force.
This test component simulates a one-dimensional translational mechanical system to validate the behavior of absolute sensors.
A mass (`body`) is subjected to a constant force (`force`, driven by `constant1`). One side of the force element is connected to
a fixed point (`ground`), and the other side acts on the mass. The sensors (`position_sensor`, `speed_sensor`, `acceleration_sensor`)
are then attached to this mass to measure its absolute position, speed, and acceleration, respectively.
The `metadata` section includes a test case that checks if the sensor outputs match these expected dynamics.
"""
test component Sensors
"Represents the translational mass being sensed."
body = TranslationalComponents.Components.Mass(m = 1, L = 0) {
"Dyad": {"placement": {"diagram": {"x1": 285, "x2": 385, "y1": 130, "y2": 230}}}
}
"Represents the force applied to the mass."
force = TranslationalComponents.Sources.Force() {
"Dyad": {"placement": {"diagram": {"x1": 155, "x2": 255, "y1": 130, "y2": 230}}}
}
"Provides a constant signal input (k=1) to the force component."
constant1 = BlockComponents.Sources.Constant(k = 1) {"Dyad": {"placement": {"diagram": {"x1": 20, "x2": 120, "y1": 20, "y2": 120}}}}
"Represents the fixed mechanical ground."
ground = TranslationalComponents.Components.Fixed() {
"Dyad": {"placement": {"diagram": {"x1": 285, "x2": 385, "y1": 305, "y2": 405}}}
}
"Sensor to measure the absolute speed of the connected flange."
speed_sensor = TranslationalComponents.Sensors.VelocitySensor() {
"Dyad": {"placement": {"diagram": {"x1": 415, "x2": 515, "y1": 130, "y2": 230}}}
}
"Sensor to measure the absolute position of the connected flange."
position_sensor = TranslationalComponents.Sensors.PositionSensor() {
"Dyad": {"placement": {"diagram": {"x1": 545, "x2": 645, "y1": 230, "y2": 330}}}
}
"Sensor to measure the absolute acceleration of the connected flange."
acceleration_sensor = TranslationalComponents.Sensors.AccelerationSensor() {
"Dyad": {"placement": {"diagram": {"x1": 680, "x2": 780, "y1": 340, "y2": 440}}}
}
relations
connect(constant1.y, force.f) {"Dyad": {"edges": [{"S": 1, "M": [{"x": 205, "y": 70}], "E": 2}]}}
connect(force.flange_b, body.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
connect(force.flange_a, ground.flange) {
"Dyad": {
"edges": [
{
"S": 1,
"M": [{"x": 140, "y": 180}, {"x": 140, "y": 280}, {"x": 335, "y": 280}],
"E": 2
}
]
}
}
connect(body.flange_b, speed_sensor.flange, position_sensor.flange, acceleration_sensor.flange) {
"Dyad": {
"edges": [
{"S": 1, "M": [], "E": -1},
{"S": -1, "M": [], "E": 2},
{"S": -1, "M": [{"x": 400, "y": 280}], "E": -2},
{"S": -2, "M": [], "E": 3},
{"S": -2, "M": [{"x": 530, "y": 390}], "E": 4}
],
"junctions": [{"x": 400, "y": 180}, {"x": 530, "y": 280}]
}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://TranslationalComponents/Example.svg"},
"tests": {
"case1": {
"stop": 5,
"initial": {"body.s": 0, "body.v": 0},
"atol": {
"body.s": 0.01,
"body.v": 0.01,
"body.a": 0.01,
"position_sensor.s": 0.01,
"speed_sensor.v": 0.01,
"acceleration_sensor.a": 0.01
},
"expect": {
"final": {
"body.s": 12.49999999,
"body.v": 4.99999999,
"body.a": 1,
"position_sensor.s": 12.49999999,
"speed_sensor.v": 4.99999999,
"acceleration_sensor.a": 1
}
}
}
}
}
}
endFlattened Source
"""
Test environment for verifying absolute position, speed, and acceleration sensors monitoring a mass driven by a constant force.
This test component simulates a one-dimensional translational mechanical system to validate the behavior of absolute sensors.
A mass (`body`) is subjected to a constant force (`force`, driven by `constant1`). One side of the force element is connected to
a fixed point (`ground`), and the other side acts on the mass. The sensors (`position_sensor`, `speed_sensor`, `acceleration_sensor`)
are then attached to this mass to measure its absolute position, speed, and acceleration, respectively.
The `metadata` section includes a test case that checks if the sensor outputs match these expected dynamics.
"""
test component Sensors
"Represents the translational mass being sensed."
body = TranslationalComponents.Components.Mass(m = 1, L = 0) {
"Dyad": {"placement": {"diagram": {"x1": 285, "x2": 385, "y1": 130, "y2": 230}}}
}
"Represents the force applied to the mass."
force = TranslationalComponents.Sources.Force() {
"Dyad": {"placement": {"diagram": {"x1": 155, "x2": 255, "y1": 130, "y2": 230}}}
}
"Provides a constant signal input (k=1) to the force component."
constant1 = BlockComponents.Sources.Constant(k = 1) {"Dyad": {"placement": {"diagram": {"x1": 20, "x2": 120, "y1": 20, "y2": 120}}}}
"Represents the fixed mechanical ground."
ground = TranslationalComponents.Components.Fixed() {
"Dyad": {"placement": {"diagram": {"x1": 285, "x2": 385, "y1": 305, "y2": 405}}}
}
"Sensor to measure the absolute speed of the connected flange."
speed_sensor = TranslationalComponents.Sensors.VelocitySensor() {
"Dyad": {"placement": {"diagram": {"x1": 415, "x2": 515, "y1": 130, "y2": 230}}}
}
"Sensor to measure the absolute position of the connected flange."
position_sensor = TranslationalComponents.Sensors.PositionSensor() {
"Dyad": {"placement": {"diagram": {"x1": 545, "x2": 645, "y1": 230, "y2": 330}}}
}
"Sensor to measure the absolute acceleration of the connected flange."
acceleration_sensor = TranslationalComponents.Sensors.AccelerationSensor() {
"Dyad": {"placement": {"diagram": {"x1": 680, "x2": 780, "y1": 340, "y2": 440}}}
}
relations
connect(constant1.y, force.f) {"Dyad": {"edges": [{"S": 1, "M": [{"x": 205, "y": 70}], "E": 2}]}}
connect(force.flange_b, body.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
connect(force.flange_a, ground.flange) {
"Dyad": {
"edges": [
{
"S": 1,
"M": [{"x": 140, "y": 180}, {"x": 140, "y": 280}, {"x": 335, "y": 280}],
"E": 2
}
]
}
}
connect(body.flange_b, speed_sensor.flange, position_sensor.flange, acceleration_sensor.flange) {
"Dyad": {
"edges": [
{"S": 1, "M": [], "E": -1},
{"S": -1, "M": [], "E": 2},
{"S": -1, "M": [{"x": 400, "y": 280}], "E": -2},
{"S": -2, "M": [], "E": 3},
{"S": -2, "M": [{"x": 530, "y": 390}], "E": 4}
],
"junctions": [{"x": 400, "y": 180}, {"x": 530, "y": 280}]
}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://TranslationalComponents/Example.svg"},
"tests": {
"case1": {
"stop": 5,
"initial": {"body.s": 0, "body.v": 0},
"atol": {
"body.s": 0.01,
"body.v": 0.01,
"body.a": 0.01,
"position_sensor.s": 0.01,
"speed_sensor.v": 0.01,
"acceleration_sensor.a": 0.01
},
"expect": {
"final": {
"body.s": 12.49999999,
"body.v": 4.99999999,
"body.a": 1,
"position_sensor.s": 12.49999999,
"speed_sensor.v": 4.99999999,
"acceleration_sensor.a": 1
}
}
}
}
}
}
endTest Cases
Test Case case1
Related
Examples
Experiments
Analyses
Tests