Importing a robot arm multibody model from a URDF file#
The purpose of this notebook is to
demonstrate the creation of a
Karana.Dynamics.Multibodyinstance for a robot arm from a URDF model fileshow the structure of the loaded model
show a 3D visualization of the robot arm
serve as a
hello worldscript for verifying a properkdFlexinstallation
Resources
Acknowledgements The Barrett WAM urdf is sourced from the public repository barrett-ros2-pkg. Thank you to the authors and contributors.
Import kdFlex Python modules objects for use later
from pathlib import Path
import atexit
import Karana.Core as kc
import Karana.Frame as kf
import Karana.Dynamics.SOADyn_types as kdt
import Karana.KUtils.BasicPrefab as kub
Build the filepath to the URDF file we will import
resources = Path().absolute().parent / "resources"
urdf_file = resources / "wam7dof" / "wam7dof_hand.urdf"
Import the URDF file to create a BasicPrefabDS. The “DS” is short for “Data Structure”. This is kdFlex’s native, file-format agnostic way of specifying a multibody and associated KModels. We’ll use this later on to instantiate the multibody.
basic_prefab_ds = kub.BasicPrefabDS.fromFile(urdf_file)
Create a Karana.Frame.FrameContainer to manager the frames layer.
frame_container = kf.FrameContainer("root")
Instantiate and configure the Karana.Dynamics.Multibody based on the BasicPrefabDS description.
prefab, prop = kub.BasicPrefab.createStandalone(basic_prefab_ds, frame_container)
multibody = prop.getSubTree().multibody()
Finalize the model to get it ready for use.
multibody.ensureHealthy()
multibody.resetData()
Set up the 3D graphics.
cleanup_viz, graphics = multibody.setupGraphics(port=0)
graphics.defaultCamera().pointCameraAt(
offset=[0.2, 0.5, 1.7],
target=[0, 0, 1],
up=[1, 0, 0],
)
del graphics
Display the bodies in the multibody model.
multibody.displayModel()
[WebUI] Web server is running on port 46277
You may be able to connect in your browser at:
http://newton:46277
LEGEND: <body number> <body name> <parent body> <hinge type> [prescribed subhinges] <U dofs/offset> [flex dofs/offset]
Body Parent Hinge Dofs
____ ______ _____ ____
1. FirstLink wam7dof_MBVROOT_ REVOLUTE 1/0
2. SecondLink FirstLink REVOLUTE 1/1
3. ThirdLink SecondLink REVOLUTE 1/2
4. FourthLink ThirdLink REVOLUTE 1/3
5. FifthLink FourthLink REVOLUTE 1/4
6. SixthLink FifthLink REVOLUTE 1/5
7. SeventhLink SixthLink REVOLUTE 1/6
8. bhand_base SeventhLink LOCKED 0/7
9. bhand_link11 bhand_base REVOLUTE 1/7
10. bhand_link12 bhand_link11 REVOLUTE 1/8
11. bhand_link13 bhand_link12 REVOLUTE 1/9
12. bhand_link21 bhand_base REVOLUTE 1/10
13. bhand_link22 bhand_link21 REVOLUTE 1/11
14. bhand_link23 bhand_link22 REVOLUTE 1/12
15. bhand_link32 bhand_base REVOLUTE 1/13
16. bhand_link33 bhand_link32 REVOLUTE 1/14
____
15
Display the topological structure of the multibody system
multibody.dumpTree()
Nodes
---
LEGEND: [<hinge type> <prescribed subhinges>] <body name>[/num embedded bodies > 0] <flex dofs > 0>
|-wam7dof_MBVROOT_
|-[REVOLUTE] FirstLink
|-[REVOLUTE] SecondLink
|-[REVOLUTE] ThirdLink
|-[REVOLUTE] FourthLink
|-[REVOLUTE] FifthLink
|-[REVOLUTE] SixthLink
|-[REVOLUTE] SeventhLink
|-[LOCKED] bhand_base
|-[REVOLUTE] bhand_link11
|-[REVOLUTE] bhand_link12
|-[REVOLUTE] bhand_link13
|-[REVOLUTE] bhand_link21
|-[REVOLUTE] bhand_link22
|-[REVOLUTE] bhand_link23
|-[REVOLUTE] bhand_link32
|-[REVOLUTE] bhand_link33
Animate the graphics by articulating the individual joints.
multibody.articulateBodies()
Cleanup
def cleanup():
"""Cleanup the simulation."""
global basic_prefab_ds, prefab
del basic_prefab_ds, prefab
kc.discard(prop)
cleanup_viz()
kc.discard(multibody)
kc.discard(frame_container)
atexit.register(cleanup)
<function __main__.cleanup()>