Skip to content

Commit

Permalink
Merge pull request #47 from JuliaComputing/freebody_animation
Browse files Browse the repository at this point in the history
Freebody animation
  • Loading branch information
baggepinnen authored Nov 9, 2023
2 parents 518f7f1 + 2f2dcca commit 5c529b5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
44 changes: 43 additions & 1 deletion docs/src/examples/free_motion.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,46 @@ The figure indicates that the body is falling freely, experiencing a constant ac
```@example FREE_MOTION
show(stdout, MIME"text/plain"(), world) # hide
nothing # hide
```
```


If we instead model a body suspended in springs without the presence of any joint, we need to give the body state variables. We do this by saying `isroot = true` when we create the body.

```@example FREE_MOTION
@named begin
body = BodyShape(m = 1, I_11 = 1, I_22 = 1, I_33 = 1, r = [0.4, 0, 0],
r_0 = [0.2, -0.5, 0.1], isroot = true)
bar2 = FixedTranslation(r = [0.8, 0, 0])
spring1 = Multibody.Spring(c = 20, s_unstretched = 0)
spring2 = Multibody.Spring(c = 20, s_unstretched = 0)
end
eqs = [connect(bar2.frame_a, world.frame_b)
connect(spring1.frame_b, body.frame_a)
connect(bar2.frame_b, spring2.frame_a)
connect(spring1.frame_a, world.frame_b)
connect(body.frame_b, spring2.frame_b)]
@named model = ODESystem(eqs, t,
systems = [
world,
body,
bar2,
spring1,
spring2,
])
ssys = structural_simplify(IRSystem(model))
prob = ODEProblem(ssys, [], (0, 10))
sol = solve(prob, Rodas5P())
@assert SciMLBase.successful_retcode(sol)
plot(sol, idxs = [body.r_0...])
```

```@example FREE_MOTION
import CairoMakie
Multibody.render(model, sol, z=-3, R = Rotations.RotXYZ(0.2, -0.2, 0), filename = "free_body.gif")
nothing # hide
```
![free_body](free_body.gif)
2 changes: 1 addition & 1 deletion src/components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ The `BodyShape` component is similar to a [`Body`](@ref), but it has two frames
@component function BodyShape(; name, m = 1, r = [0, 0, 0], r_cm = 0.5*r, r_0 = 0, radius = 0.08, kwargs...)
systems = @named begin
frameTranslation = FixedTranslation(r = r)
body = Body(; r_cm, kwargs...)
body = Body(; r_cm, r_0, kwargs...)
frame_a = Frame()
frame_b = Frame()
end
Expand Down

0 comments on commit 5c529b5

Please sign in to comment.