# RigidBodyDynamics.jl attaching a new rigid body to the system

**URL:** https://discourse.julialang.org/t/rigidbodydynamics-jl-attaching-a-new-rigid-body-to-the-system/17451
**Category:** Modelling & Simulations
**Created:** [November 12, 2018, 8:45pm UTC](https://discourse.julialang.org/t/rigidbodydynamics-jl-attaching-a-new-rigid-body-to-the-system/17451 "2018-11-12T20:45:54Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![phelipe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phelipe/32/14643_2.png) [@phelipe](https://discourse.julialang.org/u/phelipe)
#### Post date: [November 12, 2018, 8:45pm UTC](https://discourse.julialang.org/t/rigidbodydynamics-jl-attaching-a-new-rigid-body-to-the-system/17451/1 "2018-11-12T20:45:54Z")

</div>

Is it possible to add an extra load to a mechanism created from an urdf? For example, add a sphere to the last joint of a system. Can RigidBodyDynamics.attach! be used for this?

---

<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: [November 13, 2018, 1:41am UTC](https://discourse.julialang.org/t/rigidbodydynamics-jl-attaching-a-new-rigid-body-to-the-system/17451/2 "2018-11-13T01:41:50Z")

</div>

> Can RigidBodyDynamics.attach! be used for this?

Yep, that’s what it’s for. You could attach it using the `Fixed` joint type and then optionally call `removed_fixed_tree_joints!(mechanism)` to merge the rigid bodies connected by the fixed joint for efficiency.

---

<div class="post-metadata">

### Author: ![phelipe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phelipe/32/14643_2.png) [@phelipe](https://discourse.julialang.org/u/phelipe)
#### Post date: [November 17, 2018, 9:22pm UTC](https://discourse.julialang.org/t/rigidbodydynamics-jl-attaching-a-new-rigid-body-to-the-system/17451/3 "2018-11-17T21:22:35Z")

</div>

How can I do this in a mechanism obtained from an urdf file?

```julia
robot = getmechanism("acrobot")
axis = SVector(0., 1., 0.) # joint axis
I_1 = 0.333 # moment of inertia about joint axis
c_1 = -0.15 # center of mass location with respect to joint axis
m_1 = 5. # mass
frame1 = CartesianFrame3D("new") # the reference frame in which the spatial inertia will be expressed
inertia1 = SpatialInertia(frame1, I_1 * axis * axis', m_1 * SVector(0, 0, c_1), m_1)
body = RigidBody(inertia1)
attach!(robot, ? , body, Fixed)

```

---

<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: [November 17, 2018, 11:47pm UTC](https://discourse.julialang.org/t/rigidbodydynamics-jl-attaching-a-new-rigid-body-to-the-system/17451/4 "2018-11-17T23:47:50Z")

</div>

`?` in your code should be a body that’s already part of `robot` (e.g. `last(bodies(robot))`). The fourth argument should be a `Joint`, not the type of a `JointType`. It’s exactly the same as in cell 9 of [the quickstart notebook](https://github.com/JuliaRobotics/RigidBodyDynamics.jl/blob/master/notebooks/Quickstart%20-%20double%20pendulum/Quickstart%20-%20double%20pendulum.ipynb). It doesn’t matter whether the `Mechanism` you’re `attach!`ing a new body to was created directly using API calls or using `parse_urdf`. See also the [documentation for `attach!`](http://www.juliarobotics.org/RigidBodyDynamics.jl/stable/mechanism.html#RigidBodyDynamics.attach!-Union%7BTuple%7BT%7D,%20Tuple%7BMechanism%7BT%7D,RigidBody%7BT%7D,RigidBody%7BT%7D,Joint%7BT,JT%7D%20where%20JT%3C:JointType%7BT%7D%7D%7D%20where%20T) if you hadn’t seen it yet, and feel free to open a documentation PR if anything is unclear there.

---

<div class="post-metadata">

### Author: ![phelipe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phelipe/32/14643_2.png) [@phelipe](https://discourse.julialang.org/u/phelipe)
#### Post date: [November 18, 2018, 3:11pm UTC](https://discourse.julialang.org/t/rigidbodydynamics-jl-attaching-a-new-rigid-body-to-the-system/17451/5 "2018-11-18T15:11:35Z")

</div>

Thank you!
