From 774b113f59001f2a265cc6c8598f2d3acbc5e84f Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Fri, 16 Aug 2024 12:06:02 +0200 Subject: [PATCH] update logo to use wheel and spherical joints --- docs/src/index.md | 41 +++++++++++++++++++++++++---------------- src/frames.jl | 1 + src/wheels.jl | 19 ++++++++++++------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/docs/src/index.md b/docs/src/index.md index 607941be..d43af7dc 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -23,37 +23,45 @@ radius_large = length_scale*0.3 @mtkmodel Logo begin @components begin world = World(render=false) - revl = Revolute(; radius = radius_large, color=JULIASIM_PURPLE, axisflange=true) - revl2 = Revolute(; radius = radius_large, color=JULIASIM_PURPLE, axisflange=true) + + # revl = Revolute(; radius = radius_large, color=JULIASIM_PURPLE, axisflange=true) + revl = Spherical(; radius = radius_large, color=JULIASIM_PURPLE, state=true, phid=[3, 3, 3]) + move_up = FixedTranslation(r=[0, radius_large, 0], render=false) # To shift revolute up with radius of wheel + + # revl2 = Revolute(; radius = radius_large, color=JULIASIM_PURPLE, axisflange=true) + + revl2 = RollingWheel(; radius = radius_large, color=JULIASIM_PURPLE, m=1, I_axis=0.1, I_long=0.1, x0=0, state_priority=1000) + revr = Revolute(; radius = radius_small, color=JULIASIM_PURPLE, axisflange=true) bodyl = Body(m=1, radius = radius_small, color=JULIASIM_PURPLE) - bodyr = Body(m=1, radius = radius_large, color=JULIASIM_PURPLE) + bodyr = Body(m=1, radius = radius_large, color=JULIASIM_PURPLE, state_priority=-1) bar_top = FixedTranslation(r=length_scale*[1, 0.05, 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) + # 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(world.frame_b, move_up.frame_a) + connect(move_up.frame_b, revl.frame_a) connect(revl.frame_b, barl.frame_a) connect(barl.frame_b, bodyl.frame_a) - connect(world.frame_b, revl2.frame_a) - connect(revl2.frame_b, bar_top.frame_a) + # connect(world.frame_b, revl2.frame_a) + connect(revl2.frame_a, bar_top.frame_a) connect(bar_top.frame_b, revr.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(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(revl.support, damperl.flange_b) + # connect(revl2.support, damperl2.flange_b) connect(revr.support, damperr.flange_b) end end @@ -61,14 +69,15 @@ end @named logo = Logo() logo = complete(logo) ssys = structural_simplify(IRSystem(logo)) + prob = ODEProblem(ssys, [], (0.0, 3.51)) -sol = solve(prob, Rodas5P()) -Plots.plot(sol) +sol = solve(prob, Tsit5()) +# Plots.plot(sol) import GLMakie framerate = 30 -timevec = [zeros(30); range(sol.t[1], sol.t[end], step=1/framerate)] |> reverse -render(logo, sol, timevec; z=-2.5, x=0, y=-0.5, lookat=[0.2,-0.5, 0], filename="JuliaSim_logo.gif", framerate) +timevec = [zeros(40); range(sol.t[1], sol.t[end], step=1/framerate)] |> reverse +render(logo, sol, timevec; z=-2.5, x=0, y=-0.5, lookat=[0.2,-0.5+radius_large, 0], filename="JuliaSim_logo.gif", framerate) ``` ![animated logo](JuliaSim_logo.gif) diff --git a/src/frames.jl b/src/frames.jl index f4f0c568..07d64bf2 100644 --- a/src/frames.jl +++ b/src/frames.jl @@ -1,6 +1,7 @@ @connector function Frame(; name, varw = false, r_0 = zeros(3), render=false, length=1.0, radius=0.1) @variables r_0(t)[1:3]=r_0 [ description = "Position vector directed from the origin of the world frame to the connector frame origin, resolved in world frame", + state_priority=-1, ] @variables f(t)[1:3] [ connect = Flow, diff --git a/src/wheels.jl b/src/wheels.jl index 84445739..70f93b81 100644 --- a/src/wheels.jl +++ b/src/wheels.jl @@ -52,14 +52,17 @@ angles: Angles to rotate world-frame into frame_a around y-, z-, x-axis # Connector frames - `frame_a`: Frame for the wheel joint """ -@component function RollingWheelJoint(; name, radius, angles = zeros(3), der_angles=zeros(3), x0=0, y0 = radius, z0=0, sequence = [2, 3, 1], iscut=false) - @parameters begin radius = radius, [description = "Radius of the wheel"] end +@component function RollingWheelJoint(; name, radius, angles = zeros(3), der_angles=zeros(3), x0=0, y0 = radius, z0=0, sequence = [2, 3, 1], iscut=false, color = [1, 0, 0, 1], state_priority = 15) + @parameters begin + radius = radius, [description = "Radius of the wheel"] + color[1:4] = color, [description = "Color of the wheel in animations"] + end @variables begin - (x(t) = x0), [state_priority = 15, description = "x-position of the wheel axis"] + (x(t) = x0), [state_priority = state_priority, description = "x-position of the wheel axis"] (y(t) = y0), [state_priority = 0, description = "y-position of the wheel axis"] - (z(t) = z0), [state_priority = 15, description = "z-position of the wheel axis"] + (z(t) = z0), [state_priority = state_priority, description = "z-position of the wheel axis"] (angles(t)[1:3] = angles), - [state_priority = 5, description = "Angles to rotate world-frame into frame_a around z-, y-, x-axis"] + [state_priority = state_priority, description = "Angles to rotate world-frame into frame_a around z-, y-, x-axis"] (der_angles(t)[1:3] = der_angles), [state_priority = 5, description = "Derivatives of angles"] (r_road_0(t)[1:3] = zeros(3)), [ @@ -162,7 +165,8 @@ angles: Angles to rotate world-frame into frame_a around y-, z-, x-axis zeros(3) .~ collect(frame_a.f) + resolve2(Ra, f_wheel_0) zeros(3) .~ collect(frame_a.tau) + resolve2(Ra, cross(delta_0, f_wheel_0))] - compose(ODESystem(equations, t; name), frame_a) + sys = compose(ODESystem(equations, t; name=:nothing), frame_a) + add_params(sys, [color;]; name) end """ @@ -211,7 +215,8 @@ with the wheel itself. A [`Revolute`](@ref) joint rotationg around `n = [0, 1, 0 I_33 = I_axis, I_21 = 0, I_31 = 0, - I_32 = 0) + I_32 = 0, + render = false) end pars = @parameters begin radius = radius, [description = "Radius of the wheel"]