Skip to content

Commit c94b264

Browse files
authored
add SphericalSpherical and UniversalSpherical joints (#109)
* add SphericalSpherical and UniversalSpherical joints supersedes #91 * add rendering * upper bound MTK for now * up
1 parent 9d7e3ee commit c94b264

File tree

6 files changed

+469
-8
lines changed

6 files changed

+469
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ FileIO = "1"
2828
JuliaSimCompiler = "0.1.12"
2929
LinearAlgebra = "1.6"
3030
MeshIO = "0.4"
31-
ModelingToolkit = "9"
31+
ModelingToolkit = "9.0 - 9.26"
3232
ModelingToolkitStandardLibrary = "2.7.2"
3333
Rotations = "1.4"
3434
StaticArrays = "1"

ext/Render.jl

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ function get_systemtype(sys)
6767
eval(meta.type)
6868
end
6969

70-
function get_color(sys, sol, default)
70+
function get_color(sys, sol, default, var_name = :color)
7171
try
72-
Makie.RGBA(sol(sol.t[1], idxs=collect(sys.color))...)
72+
Makie.RGBA(sol(sol.t[1], idxs=collect(getproperty(sys, var_name)))...)
7373
catch
7474
if default isa AbstractVector
7575
Makie.RGBA(default...)
@@ -505,6 +505,38 @@ function render!(scene, ::typeof(BodyBox), sys, sol, t)
505505
true
506506
end
507507

508+
function render!(scene, ::typeof(UniversalSpherical), sys, sol, t)
509+
sphere_diameter = Float32(sol(sol.t[1], idxs=sys.sphere_diameter))
510+
sphere_color = get_color(sys, sol, [1, 0.2, 1, 0.9], :sphere_color)
511+
rod_width = Float32(sol(sol.t[1], idxs=sys.rod_width))
512+
rod_height = Float32(sol(sol.t[1], idxs=sys.rod_height))
513+
rod_color = get_color(sys, sol, [0, 0.1, 1, 0.9], :rod_color)
514+
cylinder_length = Float32(sol(sol.t[1], idxs=sys.cylinder_length))
515+
cylinder_diameter = Float32(sol(sol.t[1], idxs=sys.cylinder_diameter))
516+
cylinder_color = get_color(sys, sol, [1, 0.2, 0, 1], :cylinder_color)
517+
518+
# NOTE: the rod is not currently drawn as a box and the revolute cylinders are not drawn at all
519+
r_0a = get_fun(sol, collect(sys.frame_a.r_0))
520+
r_0b = get_fun(sol, collect(sys.frame_b.r_0))
521+
thing = @lift begin
522+
r1 = Point3f(r_0a($t))
523+
r2 = Point3f(r_0b($t))
524+
origin = r1
525+
extremity = r2
526+
Makie.GeometryBasics.Cylinder(origin, extremity, rod_width/2)
527+
end
528+
mesh!(scene, thing; color=rod_color, specular = Vec3f(1.5))
529+
530+
# render a sphere for the sperical joint at frame_b
531+
thing = @lift begin
532+
r2 = Point3f(r_0b($t))
533+
Sphere(r2, sphere_diameter/2)
534+
end
535+
mesh!(scene, thing; color=sphere_color, specular = Vec3f(1.5))
536+
537+
true
538+
end
539+
508540
function render!(scene, ::typeof(Damper), sys, sol, t)
509541
r_0a = get_fun(sol, collect(sys.frame_a.r_0))
510542
r_0b = get_fun(sol, collect(sys.frame_b.r_0))

src/Multibody.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ include("interfaces.jl")
154154
export World, world, Mounting1D, Fixed, FixedTranslation, FixedRotation, Body, BodyShape, BodyCylinder, BodyBox, Rope
155155
include("components.jl")
156156

157-
export Revolute, Prismatic, Planar, Spherical, Universal, GearConstraint, RollingWheelJoint,
158-
RollingWheel, FreeMotion, RevolutePlanarLoopConstraint
157+
export Revolute, Prismatic, Planar, Spherical, Universal, SphericalSpherical, UniversalSpherical,
158+
GearConstraint, RollingWheelJoint, RollingWheel, FreeMotion, RevolutePlanarLoopConstraint
159159
include("joints.jl")
160160

161161
export Spring, Damper, SpringDamperParallel, Torque, Force, WorldForce, WorldTorque

0 commit comments

Comments
 (0)