Skip to content

Commit

Permalink
Merge pull request #28 from JuliaComputing/SDP
Browse files Browse the repository at this point in the history
add SpringDamperParallel component
  • Loading branch information
baggepinnen authored Sep 28, 2023
2 parents 1dab5f1 + b480a21 commit ba51b31
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
5 changes: 4 additions & 1 deletion docs/src/examples/spring_damper_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ plot(
)
```

This example has two parallel spring-mass parts, the first body (`body1`) is attached directly to the spring, with no joint in parallel with the spring. In this situation, we have to set `isroot=true` for `body1` to indicate that we want to use the body variables as state. The second body (`body2`) is attached to the spring with a joint in parallel with the spring, so we can use the joint variables as state, hence `isroot=false` for `body2`.
This example has two parallel spring-mass parts, the first body (`body1`) is attached directly to the spring, with no joint in parallel with the spring. In this situation, we have to set `isroot=true` for `body1` to indicate that we want to use the body variables as state. The second body (`body2`) is attached to the spring with a joint in parallel with the spring, so we can use the joint variables as state, hence `isroot=false` for `body2`.


In this example we used separate springs and dampers, see also the component [`SpringDamperParallel`](@ref) which combines the two in one component.
2 changes: 1 addition & 1 deletion src/Multibody.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export Revolute, Prismatic, Spherical, Universal, GearConstraint, RollingWheelJo
RollingWheel, FreeMotion
include("joints.jl")

export Spring, Damper, Torque, Force
export Spring, Damper, SpringDamperParallel, Torque, Force
include("forces.jl")

export PartialCutForceBaseSensor, BasicCutForce, BasicCutTorque, CutTorque, CutForce
Expand Down
31 changes: 31 additions & 0 deletions src/forces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ additional equations to handle the mass are removed.
- `lengthFraction`: Location of spring mass with respect to `frame_a` as a fraction of the distance from `frame_a` to `frame_b` (=0: at `frame_a`; =1: at `frame_b`)
- `s_unstretched`: Length of the spring when it is unstretched
- `kwargs`: are passed to `LineForceWithMass`
See also [`SpringDamperParallel`](@ref)
"""
function Spring(; c, name, m = 0, lengthFraction = 0.5, s_unstretched = 0, kwargs...)
@named ptf = PartialTwoFrames()
Expand Down Expand Up @@ -346,6 +348,8 @@ and `D(s)` is the time derivative of `s`.
# Arguments:
- `d`: Damping coefficient
See also [`SpringDamperParallel`](@ref)
"""
function Damper(; d, name, kwargs...)
@named plf = PartialLineForce(; kwargs...)
Expand All @@ -356,3 +360,30 @@ function Damper(; d, name, kwargs...)
]
extend(ODESystem(eqs, t; name), plf)
end

"""
SpringDamperParallel(; name, c, d, s_unstretched)
Linear spring and linear damper in parallel acting as line force between `frame_a` and `frame_b`. A force `f` is exerted on the origin of `frame_b` and with opposite sign on the origin of `frame_a` along the line from the origin of `frame_a` to the origin of `frame_b` according to the equation:
```math
f = c (s - s_unstretched) + d*D(s)
```
where `c`, `s_unstretched` and `d` are parameters, `s` is the distance between the origin of `frame_a` and the origin of `frame_b` and `D(s)` is the time derivative of `s`.
"""
function SpringDamperParallel(; name, c, d, s_unstretched)
@named plf = PartialLineForce(; kwargs...)
@unpack s, f = plf

@parameters c=c [description = "spring constant", bounds = (0, Inf)]
@parameters d=d [description = "damping constant", bounds = (0, Inf)]
@parameters s_unstretched=s_unstretched [
description = "unstretched length of spring",
bounds = (0, Inf),
]

eqs = [f_d ~ d * D(s)
f ~ c * (s - s_unstretched) + f_d
# lossPower ~ f_d*der(s)
]
extend(ODESystem(eqs, t; name), plf)
end

0 comments on commit ba51b31

Please sign in to comment.