Skip to content

Commit

Permalink
frame to frame_b for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Sep 12, 2024
1 parent b76b98c commit 5dd058d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 31 deletions.
2 changes: 1 addition & 1 deletion docs/src/examples/wheel.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ This example demonstrates use of the [`PlanarMechanics.SlipBasedWheelJoint`](@re
constant = Blocks.Constant(k = 0)
end
@equations begin
connect(fixed.frame, revolute.frame_a)
connect(fixed.frame_b, revolute.frame_a)
connect(revolute.frame_b, prismatic.frame_a)
connect(prismatic.frame_b, body.frame_a)
connect(prismatic.frame_b, slipBasedWheelJoint.frame_a)
Expand Down
14 changes: 6 additions & 8 deletions src/PlanarMechanics/components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ purple = Multibody.purple
Frame fixed in the planar world frame at a given position and orientation
# Parameters:
- `x`: [m] Fixed absolute x-position, resolved in planarWorld frame
- `y`: [m] Fixed absolute y-position, resolved in planarWorld frame
- `r`: [m, m] Fixed absolute x,y-position, resolved in world frame
- `phi`: [rad] Fixed angle
# Connectors:
- `frame: 2-dim. Coordinate system
- `frame_b`: 2-dim. Coordinate system
"""
@mtkmodel Fixed begin
@parameters begin
Expand All @@ -20,13 +18,13 @@ Frame fixed in the planar world frame at a given position and orientation
end

@components begin
frame = Frame()
frame_b = Frame()
end

@equations begin
frame.x ~ r[1]
frame.y ~ r[2]
frame.phi ~ phi
frame_b.x ~ r[1]
frame_b.y ~ r[2]
frame_b.phi ~ phi
end
end

Expand Down
37 changes: 15 additions & 22 deletions test/test_PlanarMechanics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ tspan = (0.0, 3.0)
g = -9.807

@testset "Free body" begin
# https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Examples/FreeBody.mo
m = 2
I = 1
@named body = Pl.Body(; m, I)
Expand All @@ -34,14 +33,13 @@ g = -9.807
end

@testset "Pendulum" begin
# https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Examples/Pendulum.mo
@named ceiling = Pl.Fixed()
@named rod = Pl.FixedTranslation(r = [1.0, 0.0])
@named body = Pl.Body(m = 1, I = 0.1)
@named revolute = Pl.Revolute()

connections = [
connect(ceiling.frame, revolute.frame_a),
connect(ceiling.frame_b, revolute.frame_a),
connect(revolute.frame_b, rod.frame_a),
connect(rod.frame_b, body.frame_a)
]
Expand All @@ -63,13 +61,12 @@ end
end

@testset "Pendulum with body shape" begin
# https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Examples/Pendulum.mo
@named ceiling = Pl.Fixed()
@named rod = Pl.BodyShape(r = [1.0, 0.0], m=1, I=0.1)
@named revolute = Pl.Revolute()

connections = [
connect(ceiling.frame, revolute.frame_a),
connect(ceiling.frame_b, revolute.frame_a),
connect(revolute.frame_b, rod.frame_a),
]

Expand All @@ -95,7 +92,6 @@ end
end

@testset "AbsoluteAccCentrifugal" begin
# https://github.com/dzimmer/PlanarMechanics/blob/443b007bcc1522bb172f13012e2d7a8ecc3f7a9b/PlanarMechanicsTest/Sensors.mo#L221-L332
m = 1
I = 0.1
w = 10
Expand All @@ -111,7 +107,7 @@ end
@named abs_v_sensor = Pl.AbsoluteVelocity(; resolve_in_frame)

eqs = [
connect(fixed.frame, revolute.frame_a),
connect(fixed.frame_b, revolute.frame_a),
connect(revolute.frame_b, fixed_translation.frame_a),
connect(fixed_translation.frame_b, body.frame_a),
Pl.connect_sensor(body.frame_a, abs_v_sensor.frame_a)... # QUESTION: why?
Expand Down Expand Up @@ -175,15 +171,15 @@ end
Pl.connect_sensor(body1.frame_a, abs_v_sensor.frame_a)...,
Pl.connect_sensor(body1.frame_a, abs_a_sensor.frame_a)...,
Pl.connect_sensor(body1.frame_a, rel_pos_sensor1.frame_a)...,
Pl.connect_sensor(base.frame, rel_pos_sensor1.frame_b)...,
Pl.connect_sensor(base.frame_b, rel_pos_sensor1.frame_b)...,
Pl.connect_sensor(body1.frame_a, rel_pos_sensor2.frame_a)...,
Pl.connect_sensor(body2.frame_a, rel_pos_sensor2.frame_b)...,
Pl.connect_sensor(base.frame, rel_v_sensor1.frame_a)...,
Pl.connect_sensor(base.frame_b, rel_v_sensor1.frame_a)...,
Pl.connect_sensor(body1.frame_a, rel_v_sensor1.frame_b)...,
Pl.connect_sensor(body1.frame_a, rel_v_sensor2.frame_a)...,
Pl.connect_sensor(body2.frame_a, rel_v_sensor2.frame_b)...,
Pl.connect_sensor(body1.frame_a, rel_a_sensor1.frame_a)...,
Pl.connect_sensor(base.frame, rel_a_sensor1.frame_b)...,
Pl.connect_sensor(base.frame_b, rel_a_sensor1.frame_b)...,
Pl.connect_sensor(body1.frame_a, rel_a_sensor2.frame_a)...,
Pl.connect_sensor(body2.frame_a, rel_a_sensor2.frame_b)...
]
Expand All @@ -193,15 +189,15 @@ end
# connect(body1.frame_a, abs_v_sensor.frame_a),
# connect(body1.frame_a, abs_a_sensor.frame_a),
# connect(body1.frame_a, rel_pos_sensor1.frame_a),
# connect(base.frame, rel_pos_sensor1.frame_b),
# connect(base.frame_b, rel_pos_sensor1.frame_b),
# connect(body1.frame_a, rel_pos_sensor2.frame_a),
# connect(body2.frame_a, rel_pos_sensor2.frame_b),
# connect(base.frame, rel_v_sensor1.frame_a),
# connect(base.frame_b, rel_v_sensor1.frame_a),
# connect(body1.frame_a, rel_v_sensor1.frame_b),
# connect(body1.frame_a, rel_v_sensor2.frame_a),
# connect(body2.frame_a, rel_v_sensor2.frame_b),
# connect(body1.frame_a, rel_a_sensor1.frame_a),
# connect(base.frame, rel_a_sensor1.frame_b),
# connect(base.frame_b, rel_a_sensor1.frame_b),
# connect(body1.frame_a, rel_a_sensor2.frame_a),
# connect(body2.frame_a, rel_a_sensor2.frame_b),
# ]
Expand Down Expand Up @@ -265,7 +261,6 @@ end
end

@testset "Measure Demo" begin
# https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Examples/MeasureDemo.mo
@named body = Pl.Body(; m = 1, I = 0.1)
@named fixed_translation = Pl.FixedTranslation(;)
@named fixed = Pl.Fixed()
Expand All @@ -283,7 +278,7 @@ end
connections = [
connect(fixed_translation.frame_b, body.frame_a),
connect(fixed_translation1.frame_b, body1.frame_a),
connect(fixed.frame, revolute1.frame_a),
connect(fixed.frame_b, revolute1.frame_a),
connect(revolute1.frame_b, fixed_translation.frame_a),
# connect(abs_a_sensor.frame_resolve, abs_a_sensor.frame_a),
connect(revolute2.frame_b, fixed_translation1.frame_a),
Expand Down Expand Up @@ -321,7 +316,6 @@ end
end

@testset "SpringDamper" begin
# https://github.com/dzimmer/PlanarMechanics/blob/master/PlanarMechanics/Examples/SpringDamperDemo.mo
@named spring_damper = Pl.SpringDamper(;
s_relx0 = 0,
d_y = 1,
Expand All @@ -336,7 +330,7 @@ end
@named fixed_translation = Pl.FixedTranslation(; r = [-1, 0])

connections = [
connect(fixed.frame, fixed_translation.frame_a),
connect(fixed.frame_b, fixed_translation.frame_a),
connect(fixed_translation.frame_b, spring_damper.frame_a),
connect(spring_damper.frame_b, body.frame_a)
]
Expand All @@ -358,15 +352,14 @@ end
end

@testset "Spring and damper demo" begin
# https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Examples/SpringDemo.mo
@named body = Pl.Body(; m = 0.5, I = 0.1)
@named fixed = Pl.Fixed()
@named spring = Pl.Spring(; c_y = 10, s_rely0 = -0.5, c_x = 1, c_phi = 1e5)
@named damper = Pl.Damper(d = 1)
@named prismatic = Pl.Prismatic(; r=[0, 1])

connections = [
connect(fixed.frame, spring.frame_a),
connect(fixed.frame_b, spring.frame_a),
connect(spring.frame_b, body.frame_a),
connect(damper.frame_a, spring.frame_a),
connect(damper.frame_b, spring.frame_b),
Expand Down Expand Up @@ -428,7 +421,7 @@ end


# import GLMakie, Multibody
# Multibody.render(model, sol, show_axis=true, x=1, y=1, z=5, traces=[model.wheel1.frame, model.wheel2.frame])
# Multibody.render(model, sol, show_axis=true, x=1, y=1, z=5, traces=[model.wheel1.frame_a, model.wheel2.frame_a])


# plot(sol, idxs=[
Expand Down Expand Up @@ -466,13 +459,13 @@ import ModelingToolkitStandardLibrary.Mechanical.Rotational
revolute = Pl.Revolute(phi = 0, w = 0)
fixed = Pl.Fixed()
engineTorque = Rotational.ConstantTorque(tau_constant = 2)
body = Pl.Body(m = 10, I = 1, gy=0)
body = Pl.Body(m = 10, I = 1, gy=0, phi=0, w=0)
inertia = Rotational.Inertia(J = 1, phi = 0, w = 0)
constant = Blocks.Constant(k = 0)
end
@equations begin
connect(prismatic.frame_a, revolute.frame_b)
connect(revolute.frame_a, fixed.frame)
connect(revolute.frame_a, fixed.frame_b)
connect(engineTorque.flange, inertia.flange_a)
connect(body.frame_a, prismatic.frame_b)
connect(slipBasedWheelJoint.frame_a, prismatic.frame_b)
Expand Down

0 comments on commit 5dd058d

Please sign in to comment.