Move a Gantry
You have a gantry (a Cartesian robot with linear axes) and need to move it to specific positions. You can either control axes directly with the gantry API or use the motion service for planned, collision-aware movement.
Direct axis control
Use the gantry component API for simple, direct movements.
from viam.components.gantry import Gantry
gantry = Gantry.from_robot(machine, "my-gantry")
# Read current position (mm for each axis)
positions = await gantry.get_position()
print(f"Current positions: {positions}")
# Read axis lengths
lengths = await gantry.get_lengths()
print(f"Axis lengths: {lengths}")
# Move to a specific position
await gantry.move_to_position(positions=[200, 300, 100])
import "go.viam.com/rdk/components/gantry"
myGantry, err := gantry.FromRobot(machine, "my-gantry")
if err != nil {
logger.Fatal(err)
}
positions, err := myGantry.Position(ctx, nil)
if err != nil {
logger.Fatal(err)
}
fmt.Printf("Current positions: %v\n", positions)
lengths, err := myGantry.Lengths(ctx, nil)
if err != nil {
logger.Fatal(err)
}
fmt.Printf("Axis lengths: %v\n", lengths)
err = myGantry.MoveToPosition(ctx, []float64{200, 300, 100}, nil)
if err != nil {
logger.Fatal(err)
}
Motion-planned movement
For complex paths or collision avoidance, use the motion service.
from viam.services.motion import MotionClient
from viam.proto.common import PoseInFrame, Pose
motion_service = MotionClient.from_robot(machine, "builtin")
destination = PoseInFrame(
reference_frame="world",
pose=Pose(x=200, y=300, z=100, o_x=0, o_y=0, o_z=1, theta=0)
)
await motion_service.move(
component_name="my-gantry",
destination=destination,
)
destination := referenceframe.NewPoseInFrame("world",
spatialmath.NewPose(
r3.Vector{X: 200, Y: 300, Z: 100},
&spatialmath.OrientationVectorDegrees{OX: 0, OY: 0, OZ: 1, Theta: 0},
))
_, err = motionService.Move(ctx, motion.MoveReq{
ComponentName: "my-gantry",
Destination: destination,
})
What’s Next
- Move Arm to Pose: similar workflow for robot arms.
- Define Obstacles: add obstacle geometry for collision avoidance.
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!