Gantry Component

A robotic gantry is a mechanical system of linear actuators used to hold and position an end effector. A 3D printer is an example of a three-axis gantry where each linear actuator can move the print head along one axis. The linear rail design makes gantries a common and reliable system for simple positioning and placement tasks.

This component abstracts the hardware of a gantry to give you an easy interface for coordinated control of linear actuators, even many at once (multi-axis).

Example of what a multi-axis robot gantry looks like as a black and white illustration of an XX YY mechanical gantry.

Gantry components can only be controlled in terms of linear motion (you cannot rotate them). Each gantry can only move in one axis within the limits of the length of the linear rail.

Most machines with a gantry need at least the following hardware:

  • A board or controller component that can detect changes in voltage on GPIO pins
  • A motor that can move linear rails
  • Limit switches, to attach to the ends of the gantry’s axis

Supported models

To use your gantry with Viam, check whether one of the following built-in models or modular resources supports your gantry.

Built-in models

For configuration information, click on the model name:

ModelDescription
fakeA model used for testing, with no physical hardware.
single-axisA gantry with a singular linear rail.
multi-axisA gantry with multiple linear rails. Composed of multiple single-axis gantries.

Modular resources

Search for additional gantry models that you can add from the Viam Registry:

For configuration information, click on the model name:

Model
Description

Control your gantry with Viam’s client SDK libraries

To get started using Viam’s SDKs to connect to and control your machine, go to your machine’s page on the Viam app, navigate to the CONNECT tab’s Code sample page, select your preferred programming language, and copy the sample code generated.

When executed, this sample code will create a connection to your machine as a client. Then control your machine programmatically by adding API method calls as shown in the following examples.

These examples assume you have a gantry called "my_gantry" configured as a component of your machine. If your gantry has a different name, change the name in the code.

Be sure to import the gantry package for the SDK you are using:

from viam.components.gantry import Gantry
import (
  "go.viam.com/rdk/components/gantry"
)

API

The gantry component supports the following methods:

Method NameDescription
GetPositionGet the current positions of the axes of the gantry in mm.
MoveToPositionMove the axes of the gantry to the desired positions.
GetLengthsGet the lengths of the axes of the gantry in mm.
StopStop the gantry from moving.
IsMovingGet if the gantry is currently moving.
GetGeometriesGet all the geometries associated with the gantry in its current configuration, in the frame of the gantry.
DoCommandSend or receive model-specific commands.
CloseSafely shut down the resource and prevent further use.

GetPosition

Get the current positions of the axis of the gantry (mm).

Parameters:

  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (List[float]): A list of the position of the axes of the gantry in millimeters.

For more information, see the Python SDK Docs.

my_gantry = Gantry.from_robot(robot=robot, name="my_gantry")

# Get the current positions of the axes of the gantry in millimeters.
positions = await my_gantry.get_position()

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • ([]float64): A list of the position of the axes of the gantry in millimeters.
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myGantry, err := gantry.FromRobot(robot, "my_gantry")

// Get the current positions of the axes of the gantry in millimeters.
position, err := myGantry.Position(context.Background(), nil)

MoveToPosition

Move the axes of the gantry to the desired positions (mm) at the requested speeds (mm/sec).

Parameters:

  • positions (List[float]): A list of positions for the axes of the gantry to move to, in millimeters.
  • speeds (List[float]): A list of speeds in millimeters per second for the gantry to move at respective to each axis.
  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • None

For more information, see the Python SDK Docs.

my_gantry = Gantry.from_robot(robot=robot, name="my_gantry")

# Create a list of positions for the axes of the gantry to move to. Assume in
# this example that the gantry is multi-axis, with 3 axes.
examplePositions = [1, 2, 3]

exampleSpeeds = [3, 9, 12]

# Move the axes of the gantry to the positions specified.
await my_gantry.move_to_position(
    positions=examplePositions, speeds=exampleSpeeds)

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • positions ([]float64): A list of positions for the axes of the gantry to move to, in millimeters.
  • speeds ([]float64): A list of speeds in millimeters per second for the gantry to move at respective to each axis.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myGantry, err := gantry.FromRobot(robot, "my_gantry")

// Create a list of positions for the axes of the gantry to move to. Assume in this example that the gantry is multi-axis, with 3 axes.
examplePositions = []float64{1, 2, 3}

exampleSpeeds = []float64{3, 9, 12}

// Move the axes of the gantry to the positions specified.
myGantry.MoveToPosition(context.Background(), examplePositions, exampleSpeeds, nil)

Home

Run the homing sequence of the gantry to re-calibrate the axes with respect to the limit switches.

Parameters:

  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (boolean): Whether the gantry has run the homing sequence successfully.

For more information, see the Python SDK Docs.

my_gantry = Gantry.from_robot(robot=robot, name="my_gantry")

await my_gantry.home()

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • (bool): Whether the gantry has run the homing sequence successfully.
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myGantry, err := gantry.FromRobot(robot, "my_gantry")

myGantry.Home(context.Background(), nil)

GetLengths

Get the lengths of the axes of the gantry (mm).

Parameters:

  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (List[float]): A list of the lengths of the axes of the gantry in millimeters.

For more information, see the Python SDK Docs.

my_gantry = Gantry.from_robot(robot=robot, name="my_gantry")

# Get the lengths of the axes of the gantry in millimeters.
lengths_mm = await my_gantry.get_lengths()

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • ([]float64): A list of the lengths of the axes of the gantry in millimeters.
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myGantry, err := gantry.FromRobot(robot, "my_gantry")

// Get the lengths of the axes of the gantry in millimeters.
lengths_mm, err := myGantry.Lengths(context.Background(), nil)

Stop

Stop all motion of the gantry.

Parameters:

  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • None

For more information, see the Python SDK Docs.

my_gantry = Gantry.from_robot(robot=robot, name="my_gantry")

# Stop all motion of the gantry. It is assumed that the gantry stops
# immediately.
await my_gantry.stop()

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myGantry, err := gantry.FromRobot(robot, "my_gantry")

// Stop all motion of the gantry. It is assumed that the gantry stops immediately.
myGantry.Stop(context.Background(), nil)

IsMoving

Get if the gantry is currently moving.

Parameters:

  • None

Returns:

  • (bool): If it is true or false that the gantry is currently moving.

For more information, see the Python SDK Docs.

my_gantry = Gantry.from_robot(robot=robot, name="my_gantry")

# Stop all motion of the gantry. It is assumed that the
# gantry stops immediately.
await my_gantry.stop()

# Print if the gantry is currently moving.
print(my_gantry.is_moving())

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.

Returns:

  • (bool): If it is true or false that the gantry is currently moving.
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myGantry, err := gantry.FromRobot(robot, "my_gantry")

// Stop all motion of the gantry. It is assumed that the gantry stops immediately.
myGantry.Stop(context.Background(), nil)

// Log if the gantry is currently moving.
is_moving, err := myGantry.IsMoving(context.Background())

GetGeometries

Get all the geometries associated with the gantry in its current configuration, in the frame of the gantry. The motion and navigation services use the relative position of inherent geometries to configured geometries representing obstacles for collision detection and obstacle avoidance while motion planning.

Parameters:

  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

For more information, see the Python SDK Docs.

my_gantry = Gantry.from_robot(robot=robot, name="my_gantry")

geometries = await my_gantry.get_geometries()

if geometries:
    # Get the center of the first geometry
    print(f"Pose of the first geometry's centerpoint: {geometries[0].center}")

DoCommand

Execute model-specific commands that are not otherwise defined by the component API. For built-in models, model-specific commands are covered with each model’s documentation. If you are implementing your own gantry and add features that have no built-in API method, you can access them with DoCommand.

Parameters:

Returns:

my_gantry = Gantry.from_robot(robot, "my_gantry")

command = {"cmd": "test", "data1": 500}
result = my_gantry.do(command)

For more information, see the Python SDK Docs.

Parameters:

Returns:

myGantry, err := gantry.FromRobot(robot, "my_gantry")

command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myGantry.DoCommand(context.Background(), command)

For more information, see the Go SDK Code.

Close

Safely shut down the resource and prevent further use.

Parameters:

  • None

Returns:

  • None
my_gantry = Gantry.from_robot(robot, "my_gantry")

await my_gantry.close()

For more information, see the Python SDK Docs.

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.

Returns:

  • (error) : An error, if one occurred.
myGantry, err := gantry.FromRobot(robot, "my_gantry")

err := myGantry.Close(ctx)

For more information, see the Go SDK Docs.

Troubleshooting

You can find additional assistance in the Troubleshooting section.

You can also ask questions in the Community Discord and we will be happy to help.