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).

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 robots 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
- Encoded motor: See DC motor with encoder and encoder component.
- Stepper motor: See Stepper motor. Requires setting limit switches in the config of the gantry, or setting offsets in the config of the stepper motor.
- Limit switches, to attach to the ends of the gantry’s axis
Configuration
For configuration information, click on one of the supported gantry models:
Model | Description |
---|---|
fake | A model used for testing, with no physical hardware. |
single-axis | A gantry with a singular linear rail. |
multi-axis | A gantry with multiple linear rails. Composed of multiple single-axis gantries. |
Control your gantry with Viam’s client SDK libraries
To get started using Viam’s SDKs to connect to and control your robot, go to your robot’s page on the Viam app, navigate to the Code sample tab, select your preferred programming language, and copy the sample code generated.
Location secret
By default, the sample code does not include your robot location secret. We strongly recommend that you add your location secret as an environment variable and import this variable into your development environment as needed.
To show your robot’s location secret in the sample code, toggle Include secret on the Code sample tab. You can also see your location secret on the locations page.
Caution
Do not share your location secret, part secret, or robot address publicly. Sharing this information could compromise your system security by allowing unauthorized access to your robot, or to the computer running your robot.
When executed, this sample code will create a connection to your robot as a client. Then control your robot 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 robot.
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 Name | Description |
---|---|
GetPosition | Get the current positions of the axes of the gantry in mm. |
MoveToPosition | Move the axes of the gantry to the desired positions. |
Lengths | Get the lengths of the axes of the gantry in mm. |
Stop | Stop the gantry from moving. |
IsMoving | Get if the gantry is currently moving. |
DoCommand | Send or receive model-specific commands. |
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)
Lengths
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())
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:
command
(Dict[str, Any]): The command to execute.
Returns:
- (Dict[str, Any]): Result of the executed command.
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:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.cmd
(map[string]interface{}): The command to execute.
Returns:
- (map[string]interface{}): Result of the executed command.
- (error): An error, if one occurred.
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.
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.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!