2.2. Robot models

Robot models can be programatically defined, as shown in the previous examples, but in most cases, they are loaded from an existing location. COMPAS FAB supports loading models from local files, from remote Github repositories as well as from a running ROS instance.

2.2.1. Loading model from disk

The installation of COMPAS FAB includes some robot models which are used to exemplify loading from disk:

import compas
from compas.robots import LocalPackageMeshLoader
from compas.robots import RobotModel

import compas_fab

# Set high precision to import meshes defined in meters
compas.PRECISION = '12f'

# Locate the URDF file inside compas fab installation
urdf = compas_fab.get('universal_robot/ur_description/urdf/ur5.urdf')

# Create robot model from URDF
model = RobotModel.from_urdf_file(urdf)

# Also load geometry
loader = LocalPackageMeshLoader(compas_fab.get('universal_robot'), 'ur_description')
model.load_geometry(loader)

print(model)

2.2.2. Loading model from Github

Since a large amount of robot models defined in URDF are available on Github, COMPAS FAB provides a specialized loader that follows the conventions defined by ROS to locate a Robot’s model and geometry files.

import compas
from compas.robots import GithubPackageMeshLoader
from compas.robots import RobotModel

# Set high precision to import meshes defined in meters
compas.PRECISION = '12f'

# Select Github repository, package and branch where the model is stored
repository = 'ros-industrial/abb'
package = 'abb_irb6600_support'
branch = 'kinetic-devel'

github = GithubPackageMeshLoader(repository, package, branch)
urdf = github.load_urdf('irb6640.urdf')

# Create robot model from URDF
model = RobotModel.from_urdf_file(urdf)

# Also load geometry
model.load_geometry(github)

print(model)

2.2.3. Loading model from ROS

Note

The following example uses the ROS backend and loads the robot description model from it. Before running it, please make sure you have the ROS backend correctly configured and the Panda Demo started.

In most situations, we will load the robot model directly from a running ROS instance. The following code exemplifies how to do that.

import compas
from compas.robots import RobotModel
from compas_fab.backends import RosClient
from compas_fab.backends import RosFileServerLoader

# Set high precision to import meshes defined in meters
compas.PRECISION = '12f'

with RosClient() as ros:
    # Load URDF from ROS
    loader = RosFileServerLoader(ros)
    urdf = loader.load_urdf()

    # Create robot model from URDF and load geometry
    model = RobotModel.from_urdf_string(urdf)
    model.load_geometry(loader)

    print(model)

Note

For more details about ROS, go to the ROS Examples.

The ROS File Server loader (compas_fab.backends.RosFileServerLoader) allows to cache the results locally for faster reloads, or to be loaded using the local package loader.

To enable this behavior, set the corresponding parameters on constructor and assign a robot_name to enable locating the URDF:

import os

import compas
from compas.robots import RobotModel
from compas_fab.backends import RosClient
from compas_fab.backends import RosFileServerLoader

# Set high precision to import meshes defined in meters
compas.PRECISION = '12f'

with RosClient() as ros:
    # Load URDF from ROS with local cache enabled
    local_directory = os.path.join(os.path.expanduser('~'), 'robot_description')
    loader = RosFileServerLoader(ros, local_cache=True, local_cache_directory=local_directory)
    loader.robot_name = 'abb_irb1600_6_12'

    urdf = loader.load_urdf()

    # Create robot model from URDF and load geometry
    model = RobotModel.from_urdf_string(urdf)
    model.load_geometry(loader)

    print(model)

2.2.4. Visualizing robot models

Once a model is loaded, we can visualize it in our favorite design environment.

COMPAS includes the concept of artists: classes that assist with the visualization of datastructures and models, in a way that maintains the data separated from the specific CAD interfaces, while providing a way to leverage native performance of the CAD environment.

In the main library there are artists for various datastructures (meshes, networks, etc), and COMPAS FAB adds a RobotArtist to them. Robot artists allow visualizing robot models easily and efficiently.

The following example illustrates how to load an entire robot model from an open source repository and render it in Rhino:

import compas
compas.PRECISION = '12f'

from compas.robots import *
from compas_fab.rhino import RobotArtist

r = 'ros-industrial/abb'
p = 'abb_irb6600_support'
b = 'kinetic-devel'

github = GithubPackageMeshLoader(r, p, b)
urdf = github.load_urdf('irb6640.urdf')

robot = RobotModel.from_urdf_file(urdf)
robot.load_geometry(github)

RobotArtist(robot).draw_visual()