Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Translational): add AccelerationSensor #260

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Mechanical/Translational/Translational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include("components.jl")
export Force, Position, Velocity, Acceleration
include("sources.jl")

export ForceSensor, PositionSensor
export ForceSensor, PositionSensor, AccelerationSensor
include("sensors.jl")

end
39 changes: 35 additions & 4 deletions src/Mechanical/Translational/sensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

# Connectors:

- `flange`: 1-dim. translational flange
- `output`: real output
- `flange`: 1-dim. translational flange
- `output`: real output
"""
@mtkmodel ForceSensor begin
@components begin
Expand All @@ -30,8 +30,8 @@

# Connectors:

- `flange`: 1-dim. translational flange
- `output`: real output
- `flange`: 1-dim. translational flange
- `output`: real output
"""
@mtkmodel PositionSensor begin
@components begin
Expand All @@ -49,3 +49,34 @@
flange.f ~ 0.0
end
end

"""
AccelerationSensor(; name)

Linear 1D position input sensor.

# States:

- `a`: [m/s^2] measured acceleration

# Connectors:

- `flange`: 1-dim. translational flange
- `output`: real output
"""
@mtkmodel AccelerationSensor begin
@components begin
flange = MechanicalPort()
output = RealOutput()
end

@variables begin
a(t) = 0.0

Check warning on line 74 in src/Mechanical/Translational/sensors.jl

View check run for this annotation

Codecov / codecov/patch

src/Mechanical/Translational/sensors.jl#L74

Added line #L74 was not covered by tests
end

@equations begin
a ~ D(flange.v)
output.u ~ a
flange.f ~ 0.0
end
end
20 changes: 20 additions & 0 deletions test/Mechanical/translational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,24 @@ end
s_b = 2 - delta_s + 1

@test sol[s.pos_value.u][end]≈s_b atol=1e-3

@testset "AccelerationSensor" begin
@named acc = TV.AccelerationSensor()
m = 4
@named mass = TV.Mass(m = m)
@named force = TV.Force()
@named source = Sine(frequency = 2, amplitude = 1)
@named acc_output = RealOutput()
eqs = [
connect(force.f, source.output),
connect(force.flange, mass.flange),
connect(acc.flange, mass.flange),
connect(acc_output, acc.output)
]
@named sys = ODESystem(eqs, t, [], []; systems = [force, source, mass, acc, acc_output])
s = complete(structural_simplify(sys))
Comment on lines +170 to +171
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not @mtkbuild?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just following the way other tests are written 😅

prob = ODEProblem(s, [], (0.0, pi))
sol = solve(prob, Tsit5())
@test sol[sys.acc_output.u] ≈ (sol[sys.mass.f] ./ m)
end
end
Loading