Component types

Every component on your machine has a type that determines its API, which defines what methods your code can call on it. Choosing the right type means platform features like data capture, test panels, and the SDKs work with your hardware automatically.

Sensing

These components read information from the physical world.

TypeWhat it doesExamples
CameraCaptures 2D images or 3D point cloudsUSB webcams, IP cameras, depth cameras, lidar
EncoderTracks rotational or linear positionIncremental encoders, absolute encoders
Movement sensorReports position, orientation, velocity, or angular velocityGPS, IMU, accelerometer, gyroscope, odometry
Power sensorReports voltage, current, and power consumptionINA219, INA226, current clamps
SensorReturns key-value readingsTemperature, humidity, air quality, distance sensors

Actuation

These components make things move.

TypeWhat it doesExamples
ArmControls a multi-jointed robotic armxArm, UR5, custom serial arms
BaseMoves a mobile robot as a unit (no need to command individual motors)Wheeled rovers, tracked vehicles, holonomic platforms
GantryMoves along linear rails with precise positioningSingle-axis stages, multi-axis CNC gantries
GripperOpens and closes a grasping deviceParallel-jaw grippers, vacuum grippers
MotorDrives rotational or linear motion with speed and position controlDC motors, stepper motors, brushless motors
ServoMoves to precise angular positionsHobby servos, PWM-controlled actuators

Interface

These components provide low-level hardware access or human input.

TypeWhat it doesExamples
BoardExposes GPIO pins, analog readers, and digital interruptsRaspberry Pi GPIO, Arduino, custom I/O boards
ButtonReads presses from a physical buttonMomentary switches, push buttons
GenericCatch-all for hardware that doesn’t fit another typeCustom devices with non-standard interfaces
Input controllerReads human input from control devicesGamepads, joysticks, custom button panels
SwitchReads position from a multi-position switchToggle switches, selector switches

Choosing a type

Match your hardware to the type whose API best describes what it does:

  • If it produces images, use camera.
  • If it produces readings (temperature, distance, pressure), use sensor.
  • If it reports position or motion (GPS, IMU), use movement sensor.
  • If it spins or drives linear motion, use motor.
  • If it moves to an angle, use servo.
  • If you need direct GPIO access, use board.
  • If nothing fits, use generic. It provides DoCommand for arbitrary interactions.

Every type also has a DoCommand method for functionality beyond the standard API. For example, a sensor that also has a calibration routine can expose calibration through DoCommand while still using GetReadings for its primary data.

Models

Each component type has one or more models: drivers that know how to communicate with specific hardware. Some models ship with viam-server (like webcam for USB cameras or gpio for motors). Most hardware-specific models come from the Viam registry. All models work the same way regardless of where they come from.

If no model exists for your hardware, you can write a driver module that implements the standard API for your device.

Switching hardware without changing code

Because every model of a given type exposes the same API, your application code doesn’t change when you swap hardware. For example, this Python code reads a motor’s position:

motor = Motor.from_robot(robot, "drive-motor")
position = await motor.get_position()

This works whether drive-motor is configured as a gpio motor on a Raspberry Pi, a Trinamic stepper over CAN bus, or an ODrive brushless controller. To switch hardware, you change the model and attributes in your machine’s configuration. Your code stays the same.

What’s next