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.

Loading model from disk

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

from compas_robots import RobotModel
from compas_robots.resources import LocalPackageMeshLoader

import compas_fab

# Locate the URDF file inside compas fab installation
urdf = compas_fab.get("robot_library/ur10e_robot/urdf/robot_description.urdf")

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

# Also load geometry
support_package_name = ""
loader = LocalPackageMeshLoader(compas_fab.get("robot_library/ur10e_robot"), support_package_name)
model.load_geometry(loader, precision=12)

print(model)

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.

from compas_robots.resources import GithubPackageMeshLoader
from compas_robots import RobotModel

# 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, precision=12)

print(model)

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.

from compas_fab.backends import RosClient

with RosClient() as ros:
    robot = ros.load_robot(load_geometry=True, precision=12)

    print(robot.model)

Note

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

Additionally, the ROS loader allows to cache the results locally for faster reloads, to enable this behavior, pass an argument with the folder where the cache should be stored:

import os

from compas_fab.backends import RosClient

with RosClient() as ros:
    # Load complete model from ROS and set a local cache location
    local_directory = os.path.join(os.path.expanduser("~"), "robot_description", "robot_name")
    robot = ros.load_robot(load_geometry=True, local_cache_directory=local_directory, precision=12)

    print(robot.model)

Visualizing robot models

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

COMPAS includes the concept of scene objects: 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.

We use the compas_robots extension and its RobotModelObject to visualize robots easily and efficiently.

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

from compas_fab.backends import RosClient
from compas.scene import Scene

with RosClient() as ros:
    # Load complete model from ROS
    robot = ros.load_robot(load_geometry=True, precision=12)

    # Visualize robot
    scene = Scene()
    scene_object = scene.add(robot.model)
    scene.draw()