Skip to content

Commit

Permalink
add color option to revolute
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Jun 11, 2024
1 parent cd28bb8 commit 79a767b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
38 changes: 27 additions & 11 deletions examples/JuliaSim_logo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,45 @@ W(args...; kwargs...) = Multibody.world


JULIASIM_PURPLE = [87,87,219,255.0f0]./255 # RGBA
length_scale = 0.5
length_scale = 0.5 # This controls the frequency of the oscillations, smaller scale -> faster oscillations
radius_small = length_scale*0.2
radius_large = length_scale*0.3

@mtkmodel Logo begin
@components begin
world = World()
revl = Revolute(; radius = radius_large, color=JULIASIM_PURPLE)
revr = Revolute(; radius = radius_small, color=JULIASIM_PURPLE)
revl = Revolute(; radius = radius_large, color=JULIASIM_PURPLE, useAxisFlange=true)
revl2 = Revolute(; radius = radius_large, color=JULIASIM_PURPLE, useAxisFlange=true)
revr = Revolute(; radius = radius_small, color=JULIASIM_PURPLE, useAxisFlange=true)
bodyl = Body(m=1, radius = radius_small, color=JULIASIM_PURPLE)
bodyr = Body(m=1, radius = radius_large, color=JULIASIM_PURPLE)
bar_top = FixedTranslation(r=length_scale*[1, 0.05, 0], radius=length_scale*0.025, color=JULIASIM_PURPLE)
bar_l = FixedTranslation(r=length_scale*[1, -1, 0], radius=length_scale*0.025, color=JULIASIM_PURPLE)
bar_r = FixedTranslation(r=1.1*length_scale*[-1, -1, 0], radius=length_scale*0.025, color=JULIASIM_PURPLE)
barl = FixedTranslation(r=length_scale*[1, -1, 0], radius=length_scale*0.025, color=JULIASIM_PURPLE)
barr = FixedTranslation(r=1.1*length_scale*[-1, -1, 0], radius=length_scale*0.025, color=JULIASIM_PURPLE)

damperl = Rotational.Damper(d=0.1)
damperl2 = Rotational.Damper(d=0.01)
damperr = Rotational.Damper(d=0.01)
end
@equations begin
connect(revl.frame_a, world.frame_b)

connect(revl.frame_b, bar_l.frame_a)
connect(bar_l.frame_b, bodyl.frame_a)
connect(revl.frame_b, barl.frame_a)
connect(barl.frame_b, bodyl.frame_a)

connect(world.frame_b, bar_top.frame_a)
connect(world.frame_b, revl2.frame_a)
connect(revl2.frame_b, bar_top.frame_a)
connect(bar_top.frame_b, revr.frame_a)
connect(revr.frame_b, bar_r.frame_a)
connect(bar_r.frame_b, bodyr.frame_a)
connect(revr.frame_b, barr.frame_a)
connect(barr.frame_b, bodyr.frame_a)

connect(revl.axis, damperl.flange_a)
connect(revl2.axis, damperl2.flange_a)
connect(revr.axis, damperr.flange_a)

connect(revl.support, damperl.flange_b)
connect(revl2.support, damperl2.flange_b)
connect(revr.support, damperr.flange_b)
end
end

Expand All @@ -43,4 +57,6 @@ sol = solve(prob, Rodas5P())
Plots.plot(sol)

using GLMakie
render(logo, sol; z=-2, x=-0.3, y=0.3, filename="JuliaSim_logo.gif")
framerate = 30
timevec = range(sol.t[1], sol.t[end], step=1/framerate) |> reverse
render(logo, sol, timevec; z=-2, x=-0.3, y=0.3, filename="JuliaSim_logo.mp4", framerate)
13 changes: 10 additions & 3 deletions src/joints.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
function add_params(sys, params; name)
params isa AbstractVector || (params = [params...])
extend(ODESystem(Equation[], t, [], params; name), sys)
end

"""
Revolute(; name, phi0 = 0, w0 = 0, n, useAxisFlange = false)
Expand All @@ -14,12 +18,15 @@ If `useAxisFlange`, flange connectors for ModelicaStandardLibrary.Mechanics.Rota
- `support`: 1-dim. rotational flange of the drive support (assumed to be fixed in the world frame, NOT in the joint)
"""
@component function Revolute(; name, phi0 = 0, w0 = 0, n = Float64[0, 0, 1], useAxisFlange = false,
isroot = true, iscut = false, radius = 0.05, state_priority = 3.0)
isroot = true, iscut = false, radius = 0.05, color = [0.5019608f0,0.0f0,0.5019608f0,1.0f0], state_priority = 3.0)
norm(n) 1 || error("Axis of rotation must be a unit vector")
@named frame_a = Frame()
@named frame_b = Frame()
@parameters n[1:3]=n [description = "axis of rotation"]
@parameters radius = radius [description = "radius of the joint in animations"]
pars = @parameters begin
radius = radius, [description = "radius of the joint in animations"]
color[1:4] = color, [description = "color of the joint in animations (RGBA)"]
end
@variables tau(t)=0 [
connect = Flow,
state_priority = 2,
Expand Down Expand Up @@ -76,7 +83,7 @@ If `useAxisFlange`, flange connectors for ModelicaStandardLibrary.Mechanics.Rota
push!(eqs, tau ~ 0)
ODESystem(eqs, t; name=:nothing, systems=[frame_a, frame_b])
end
extend(ODESystem(Equation[], t, [], [radius]; name), sys)
add_params(sys, pars; name)
end

"""
Expand Down

0 comments on commit 79a767b

Please sign in to comment.