# RigidBodyDynamics visualization not working

**URL:** https://discourse.julialang.org/t/rigidbodydynamics-visualization-not-working/45232
**Category:** General Usage
**Tags:** question
**Created:** [August 19, 2020, 11:04pm UTC](https://discourse.julialang.org/t/rigidbodydynamics-visualization-not-working/45232 "2020-08-19T23:04:27Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![\_dominic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_dominic/32/7845_2.png) [@\_dominic](https://discourse.julialang.org/u/_dominic)
#### Post date: [August 19, 2020, 11:04pm UTC](https://discourse.julialang.org/t/rigidbodydynamics-visualization-not-working/45232/1 "2020-08-19T23:04:27Z")

</div>

I am playing with the example from the RigidBodyDynamic.jl documentation with the MeshCatMechanisms.jl. No major changes.

How do I get the last link to show?

```julia
using RigidBodyDynamics
using LinearAlgebra
using StaticArrays
using MeshCatMechanisms
using Random

g = -9.81 # gravitational acceleration in z-direction
world = RigidBody{Float64}("world")
doublependulum = Mechanism(world; gravity = SVector(0, 0, g))
axis = SVector(0., 1., 0.) # joint axis

axis = SVector(0., 1., 0.) # joint axis
I_1 = 0.333 # moment of inertia about joint axis
c_1 = -0.5 # center of mass location with respect to joint axis
m_1 = 1. # mass
frame1 = CartesianFrame3D("upper_link") # the reference frame in which the spatial inertia will be expressed
inertia1 = SpatialInertia(frame1,
    moment=I_1 * axis * axis',
    com=SVector(0, 0, c_1),
    mass=m_1)

upperlink = RigidBody(inertia1)
shoulder = Joint("shoulder", Revolute(axis))
before_shoulder_to_world = one(Transform3D, frame_before(shoulder), default_frame(world))
attach!(doublependulum, world, upperlink, shoulder, joint_pose = before_shoulder_to_world)

l_1 = -1. # length of the upper link
I_2 = 0.333 # moment of inertia about joint axis
c_2 = -0.5 # center of mass location with respect to joint axis
m_2 = 1. # mass
inertia2 = SpatialInertia(CartesianFrame3D("lower_link"),
    moment=I_2 * axis * axis',
    com=SVector(0, 0, c_2),
    mass=m_2)
lowerlink = RigidBody(inertia2)
elbow = Joint("elbow", Revolute(axis))
before_elbow_to_after_shoulder = Transform3D(
    frame_before(elbow), frame_after(shoulder), SVector(0, 0, l_1))
attach!(doublependulum, upperlink, lowerlink, elbow,
    joint_pose = before_elbow_to_after_shoulder)

state = MechanismState(doublependulum)

set_configuration!(state, shoulder, 0.3)
set_configuration!(state, elbow, 0.4)
set_velocity!(state, shoulder, 1.)
set_velocity!(state, elbow, 2.);
setdirty!(state)

using MeshCatMechanisms

vis = MechanismVisualizer(doublependulum, Skeleton(inertias = false));
open(vis)

```

I was playing with adding a point. It worked, but I cannot figure out how the link is supposed to work

```julia
frame3 = CartesianFrame3D("end_effector") # the reference frame in which the spatial inertia will be expressed
lower_link_body = findbody(doublependulum, "lower_link")
end_point = Point3D(default_frame(lower_link_body), 0., 0, l_1)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/1/2/12cb2e28b1ccca2dddd203aa973d405b17d97865.png)

---

<div class="post-metadata">

### Author: ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)
#### Post date: [August 20, 2020, 12:45am UTC](https://discourse.julialang.org/t/rigidbodydynamics-visualization-not-working/45232/2 "2020-08-20T00:45:05Z")

</div>

With `Skeleton(inertias = false)`, MechanismGeometries.jl generates a box geometry (‘rod’) between the origins of each pair of joints that is attached to the same rigid body. This is handy as a quick and dirty visualization for for closed-loop mechanisms, like the four-bar linkage example. But for kinematic trees like the double pendulum, there’s really no way for MechanismGeometries.jl to come up with appropriate geometry to draw for the ‘leaf’ links in the tree (e.g., the lower link for the double pendulum). The mechanism does not store the ‘length’ of the second link (since that’s not necessary for the dynamics), so that can’t be used to generate geometry, and you’re explicitly disabling the inertia ellipsoid visualization, which would use CoM location and moment of inertia.

You can instead define your mechanism along with visual geometries for the links in a URDF file (see e.g. [https://github.com/JuliaRobotics/RigidBodyDynamics.jl/blob/master/test/urdf/Acrobot.urdf](https://github.com/JuliaRobotics/RigidBodyDynamics.jl/blob/master/test/urdf/Acrobot.urdf) for a double pendulum, and use `URDFVisuals` instead of `Skeleton` as the geometry source). Or you can still define the mechanism layout in code as you’re doing, but manually add appropriate geometries to the nodes in the visualizer tree corresponding to the links using the `setelement!` function. See [https://github.com/JuliaRobotics/MeshCatMechanisms.jl/blob/master/examples/demo.ipynb](https://github.com/JuliaRobotics/MeshCatMechanisms.jl/blob/master/examples/demo.ipynb) for some examples, but note that you can add other geometry types as well.

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [August 20, 2020, 12:45am UTC](https://discourse.julialang.org/t/rigidbodydynamics-visualization-not-working/45232/3 "2020-08-20T00:45:19Z")

</div>

The `Skeleton` geometry source is pretty basic–it only draws sticks between joints, so a terminal link will only be obvious if you allow it to draw the inertias. If you set `inertias=true`, do you see the link?

---

<div class="post-metadata">

### Author: ![\_dominic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_dominic/32/7845_2.png) [@\_dominic](https://discourse.julialang.org/u/_dominic)
#### Post date: [August 20, 2020, 12:56am UTC](https://discourse.julialang.org/t/rigidbodydynamics-visualization-not-working/45232/4 "2020-08-20T00:56:37Z")

</div>

with `inertias=true` I get an error

```julia
ERROR: Principal inertias [-0.25, 0, 0.083] do not satisfy the triangle inequalities, so the equivalent inertial ellipsoid is not well-defined 

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/9/c9f0cc25fe32c7b8afcaaa70672874d4a90c4490.png)

---

<div class="post-metadata">

### Author: ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)
#### Post date: [August 20, 2020, 1:23am UTC](https://discourse.julialang.org/t/rigidbodydynamics-visualization-not-working/45232/5 "2020-08-20T01:23:47Z")

</div>

Ugh, yeah, that’s [https://github.com/JuliaRobotics/RigidBodyDynamics.jl/issues/399](https://github.com/JuliaRobotics/RigidBodyDynamics.jl/issues/399) which we haven’t gotten around to. Instead of `moment=I_1 * axis * axis'` you should be able to use `moment=I_1 * [0.01, 1, 1]`, for example.

---

<div class="post-metadata">

### Author: ![\_dominic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_dominic/32/7845_2.png) [@\_dominic](https://discourse.julialang.org/u/_dominic)
#### Post date: [August 20, 2020, 4:43pm UTC](https://discourse.julialang.org/t/rigidbodydynamics-visualization-not-working/45232/6 "2020-08-20T16:43:15Z")

</div>

`SDiagonal()` produces the same error. I will move to URDF files

---

<div class="post-metadata">

### Author: ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)
#### Post date: [August 21, 2020, 3:06am UTC](https://discourse.julialang.org/t/rigidbodydynamics-visualization-not-working/45232/7 "2020-08-21T03:06:45Z")

</div>

See [Adding external force RigidBodyDynamics mechansms - #4 by tkoolen](https://discourse.julialang.org/t/adding-external-force-rigidbodydynamics-mechansms/45233/4).
