Skip to content

Commit 21c487b

Browse files
committed
add length_fraction param to body
1 parent 89f73e1 commit 21c487b

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

docs/src/examples/pendulum.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ nothing # hide
7474

7575
![animation](pendulum.gif)
7676

77-
By default, the world frame is indicated using the convention x: red, y: green, z: blue. The animation shows how the simple [`Body`](@ref) represents a point mass at a particular distance `r_cm` away from its mounting flange `frame_a`. To model a more physically motivated pendulum rod, we could have used a [`BodyShape`](@ref) component, which has two mounting flanges instead of one. The [`BodyShape`](@ref) component is shown in several of the examples available in the example sections of the documentation.
77+
By default, the world frame is indicated using the convention x: red, y: green, z: blue. The animation shows how the simple [`Body`](@ref) represents a point mass with inertial properties at a particular distance `r_cm` away from its mounting flange `frame_a`. The cylinder that is shown connecting the pivot point to the body is for visualization purposes only, it does not have any inertial properties. To model a more physically motivated pendulum rod, we could have used a [`BodyShape`](@ref) component, which has two mounting flanges instead of one. The [`BodyShape`](@ref) component is shown in several of the examples available in the example sections of the documentation.
7878

7979
## Adding damping
8080
To add damping to the pendulum such that the pendulum will eventually come to rest, we add a [`Damper`](@ref) to the revolute joint. The damping coefficient is given by `d`, and the damping force is proportional to the angular velocity of the joint. To add the damper to the revolute joint, we must create the joint with the keyword argument `axisflange = true`, this adds two internal flanges to the joint to which you can attach components from the `ModelingToolkitStandardLibrary.Mechanical.Rotational` module (1-dimensional components). We then connect one of the flanges of the damper to the axis flange of the joint, and the other damper flange to the support flange which is rigidly attached to the world.

ext/Render.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ function render!(scene, ::typeof(Body), sys, sol, t)
243243
r_cm = get_fun(sol, collect(sys.r_cm))
244244
framefun = get_frame_fun(sol, sys.frame_a)
245245
radius = sol(sol.t[1], idxs=sys.radius) |> Float32
246+
length_fraction = sol(sol.t[1], idxs=sys.length_fraction) |> Float32
246247
cylinder_radius = sol(sol.t[1], idxs=sys.cylinder_radius) |> Float32
247248
thing = @lift begin # Sphere
248249
Ta = framefun($t)
@@ -265,9 +266,8 @@ function render!(scene, ::typeof(Body), sys, sol, t)
265266
tip = Point3f(Ta[1:3, 4]) # Origin of frame a in world coords
266267

267268
d = tip - point
268-
d = d ./ norm(d)
269269
# d = Point3f(Ta[1:3, 1])
270-
tip = point + 0.2f0d
270+
tip = point + length_fraction*d
271271
extremity = tip
272272
origin = point
273273

src/components.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ Representing a body with 3 translational and 3 rotational degrees-of-freedom.
240240
w_a = 0,
241241
radius = 0.05,
242242
cylinder_radius = radius/2,
243+
length_fraction = 1,
243244
air_resistance = 0.0,
244245
color = [1,0,0,1],
245246
quat=false,)
@@ -275,6 +276,7 @@ Representing a body with 3 translational and 3 rotational degrees-of-freedom.
275276
description = "Radius of the cylinder from frame to COM in animations",
276277
]
277278
@parameters color[1:4] = color [description = "Color of the body in animations (RGBA)"]
279+
@parameters length_fraction=length_fraction, [description = "Fraction of the length of the body that is the cylinder from frame to COM in animations"]
278280
# @parameters I[1:3, 1:3]=I [description="inertia tensor"]
279281

280282
@parameters I_11=I_11 [description = "Element (1,1) of inertia tensor"]
@@ -350,7 +352,7 @@ Representing a body with 3 translational and 3 rotational degrees-of-freedom.
350352
# pars = [m;r_cm;radius;I_11;I_22;I_33;I_21;I_31;I_32;color]
351353

352354
sys = ODESystem(eqs, t; name=:nothing, metadata = Dict(:isroot => isroot), systems = [frame_a])
353-
add_params(sys, [radius; cylinder_radius; color]; name)
355+
add_params(sys, [radius; cylinder_radius; color; length_fraction]; name)
354356
end
355357

356358

0 commit comments

Comments
 (0)