Find a Module for your Machine

You can extend Viam by adding a module on your machine that provides one or more modular resources (components or services):

  1. Add a module, either one from the registry or a local module. This makes the modular resource available to the machine.
  2. Then add the modular resource itself.

When you add a modular resource from the registry, the underlying module that provides it is automatically added at the same time. To add a modular resource from a local module, you must add the module first.

You can search the available modular resources from the Viam Registry here:

API
Model
Description

You can see details about each module in the Viam registry on its dedicated module page. You can integrate modules into any Viam-powered machine.

Add a modular resource from the Viam registry

The Viam registry is a central repository of modules from both Viam and the robotics community that allows you to easily extend Viam’s capabilities on your machine.

A module provides one or more modular resources (either a component or service).

Follow the instructions below depending on the type of modular resource you would like to add to your machine:

Add a modular component from the Viam registry

To add a modular component from the Viam registry to your machine:

  1. Navigate to the CONFIGURE tab of your machine’s page in the Viam app.

  2. Click the + (Create) icon next to your machine part in the left-hand menu and select Component.

  3. Browse the list of available component types, and select the specific modular component you’d like to add.

    The add a component modal showing results for the intel realsense module when searching by the category 'camera'

    You can also start typing to search for a module by name or to narrow down your search results.

    The add a component modal showing results for the intel realsense module when searching by the name 'realsense'
  4. After selecting the modular component, enter a name or use the suggested name for your modular component and click Create to add it to your machine’s component configuration.

    The add a component modal showing the intel realsense module pane, with the 'Add module' button shown

    Be sure the modular component you select supports the platform you intend to use it with, such as linux arm64. You can see which platforms the module supports at bottom of the module information screen before you add it.

When you add a modular component from the registry, it appears on the CONFIGURE tab like any other component.

If the component requires you to configure specific Attributes, navigate to the CONFIGURE tab and hover over the component in the machine part tree in the upper left-hand corner. Click on the menu and select Go to homepage to view the specific attribute requirements on the module’s GitHub page.

To delete a modular component, navigate to the component’s card on the CONFIGURE tab. Click on the icon and click Delete. Confirm your selection.

Add a modular service from the Viam registry

To add a modular service from the Viam registry to your machine:

  1. Navigate to the CONFIGURE tab of your machine’s page in the Viam app.

  2. Click the + icon next to your machine part in the left-hand menu and select Service.

  3. Browse the list of available service types and select the specific modular service you’d like to add.

    The add a component modal showing results for the mlmodelservice triton module when searching by the category 'ML Model'

    You can also start typing to search for a module by name or to narrow down your search results.

    The add a component modal showing results for the mlmodelservice triton module when searching by the name 'triton'
  4. After selecting the modular service, enter a name or use the suggested name for your modular service and click Create to add it to your machine’s service configuration.

    The add a component modal showing the mlmodelservice triton module pane, with the 'Add module' button shown

    Be sure the modular service you select supports the platform you intend to use it with, such as linux arm64. You can see which platforms the module supports at bottom of the module information screen before you add it.

When you add a modular service from the registry, it appears on the CONFIGURE tab like any other service.

If the component requires you to configure specific Attributes, navigate to the CONFIGURE tab and hover over the service in the machine part tree in the upper left-hand corner. Click on the menu and select Go to homepage to view the specific attribute requirements on the module’s GitHub page.

To delete a modular service, navigate to the service’s card on the CONFIGURE tab. Click on the menu and click Delete. Confirm your selection.

Add additional modular resources from a registry module

Once you have added a module from the Viam registry, you can add any number of the modular resources it provides to your machine by adding new components or services configured with your modular resource’s model.

Follow the same steps as when you added the first modular resource, clicking Create and Component or Service as applicable. You will be prompted to click Add module again while configuring the resource, though no duplicate module will be added to the modules section of the configuration.

Edit the configuration of a module from the Viam registry

Edit modular resources

You can edit the configuration of the modular resource or resources you have added from your module at the card matching the name you gave the resource when adding on the CONFIGURE tab.

If you prefer to use JSON, the following properties are available for all modular resources:

NameTypeInclusionDescription
namespacestringRequiredThe namespace of the API (the first part of the API namespace triplet). See Valid APIs to implement in your model
typestringRequiredThe subtype of the API (the third part of the API namespace triplet). See Valid APIs to implement in your model.
namestringRequiredWhat you want to name this instance of your modular resource.
modelstringRequiredThe full model namespace triplet of the modular resource’s model.
depends_onarrayOptionalThe name of components you want to confirm are available on your machine alongside your modular resource. Often a board. Unnecessary if you coded implicit dependencies.

All standard properties for configuration, such as attributes and depends_on, are also supported for modular resources. The attributes available vary depending on your implementation. If the module requires you to configure specific Attributes, click the Registry link in the module’s configuration card to view the specific attribute requirements on the module’s GitHub page.

{
  "components": [
    {
      "name": "<your-model-instance-name>",
      "model": "<namespace>:<repo-name>:<name>",
      "type": "<your-resource-subtype>",
      "namespace": "<your-module-namespace>",
      "attributes": {},
      "depends_on": []
    }
  ],
  "modules": [
    {
      "type": "registry",
      "name": "<module-name>",
      "module_id": "<module-namespace>:<module-name>",
      "version": "<module-version>"
    }
  ]
}

The following is an example configuration for the Intel Realsense module. The configuration adds viam:camera:realsense as a modular resource from the module viam:realsense. The custom model is configured as a component with the name “my-realsense”.

{
  "components": [
    {
      "name": "my-realsense",
      "model": "viam:camera:realsense",
      "type": "camera",
      "namespace": "rdk",
      "attributes": {
        "sensors": ["color", "depth"]
      },
      "depends_on": []
    }
  ],
  "modules": [
    {
      "type": "registry",
      "name": "viam_realsense",
      "module_id": "viam:realsense",
      "version": "0.0.3"
    }
  ]
}

Edit the module

You can also view and edit the configuration of a modular resource’s underlying module from the CONFIGURE tab:

  1. Navigate to the CONFIGURE tab of your machine’s page in the Viam app.
  2. Scroll to the card with the name of the module, as indicated by its page in the registry.

This is the Registry module card. This pane lists the deployed version of the module and the latest version available. Here, configure how a module updates.

The module card

You can also use JSON mode to configure environment variables for your module.

Configure version update management for a registry module

When you add a module to your machine, you can also configure how that module updates itself when a newer version becomes available from the Viam registry. By default, a newly-added module is set to pin to the specific patch release (Patch (X.Y.Z)) of the version you added, meaning that the module will never automatically update itself.

To allow automatic module updates when a new version of the module becomes available in the Viam registry, set the Pinned version type for your module in its module card on the CONFIGURE tab. The following update options are available:

  • Patch (X.Y.Z): Do not update to any other version. This is the default.
  • Minor (X.Y.*): Only update to newer patch releases of the same minor release branch. The module will automatically restart and update itself whenever new updates within the same minor release are available in the Viam registry. For example, use this option to permit a module with version 1.2.3 to update to version 1.2.4 or 1.2.5 but not 1.3.0 or 2.0.0.
  • Major (X.*): Only update to newer minor releases of the same major release branch. The module will automatically restart and update itself whenever new updates within the same major release are available in the Viam registry. For example, use this option to permit a module with version 1.2.3 to update to version 1.2.4 or 1.3.0 but not 2.0.0 or 3.0.0.
  • Latest: Always update to the latest version of this module available from the Viam registry as soon as a new version becomes available.

When using the Patch (X.Y.Z) version type, you may select any patch version of the module from the Version dropdown menu, including past versions if desired.

The current deployed version of your module and the latest version of that module available from the Viam registry are shown on this module card for your reference.

Use environment variables with a registry module

Some modules require that you set specific environment variables as part of configuration. You can click the Homepage link in the upper-right corner of the module configuration card to view any specific requirements on the module’s GitHub page.

Module environment variables can be either:

  • Static string values, or
  • References to a system environment variable.

For example, if your module requires a MODULE_USER environment variable, you can add it with the following configuration:

{
  "modules": [
    {
      ...
      "env": {
        "MODULE_USER": "my-username"
      }
    }
  ]
}

Or if you are using a module that requires access to an additional program or library on your machine, you can create a PATH environment variable for that module:

{
  "modules": [
    {
      ...
      "env": {
        "PATH": "/home/username/bin:${environment.PATH}"
      }
    }
  ]
}

This configures a module environment variable PATH that uses your system’s PATH (which you can view by running echo $PATH) as a base, and adds one additional filesystem path: /home/username/bin.

The notation ${environment.<ENV-VAR-NAME>}" can be used to access any system environment variable that viam-server has access to, where <ENV-VAR-NAME> represents a system environment variable, like PATH, USER, or PWD. For example, you can use ${environment.HOME}" to access the HOME environment variable for the user running viam-server.

To configure a modular resource with an environment variable, navigate to the CONFIGURE tab on your machine’s page in the Viam app, select JSON mode, and add the following env configuration to the modules section:

{
  "modules": [
    {
      "type": "registry",
      "name": "<module-name>",
      "module_id": "<module-namespace>:<module-name>",
      "version": "<module-version>",
      "env": {
        "MY_VAR": "<some-value>",
        "PATH": "<example-folder>:${environment.PATH}"
      }
    }
  ]
}
{
  "modules": [
    {
      "type": "registry",
      "name": "my-module",
      "module_id": "my-namespace:my-module",
      "version": "1.0.0",
      "env": {
        "PATH": "/home/username/bin:${environment.PATH}",
        "MY_USER": "username"
      }
    }
  ]
}

To delete an environment variable configuration, delete the env section from your smart machine’s configuration.

Default environment variables

When a module is instantiated, it has access to the following default environment variables:

NameDescription
VIAM_HOMEThe root of the viam-server configuration.
Default: $HOME/.viam
VIAM_MODULE_ROOTThe root of the module install directory. The module process uses this directory as its current working directory (cwd). This variable is useful for file navigation that is relative to the root of the module. If you are using a local module, you must set this value manually if your module requires it.
Example: /opt/my-module/verxxxx-my-module/
VIAM_MODULE_DATAA persistent folder location a module can use to store data across reboots and versions. This location is a good place to store python virtual environments.
Example: $VIAM_HOME/module-data/cloud-machine-id/my-module-name/
VIAM_MODULE_IDThe module ID of the module.
Example: viam:realsense

Local modules

If you wish to add a module to your machine without uploading it to the Viam registry, you can add your module as a local module.

You can add your own custom modules as local modules, or you can add pre-built modules written by other Viam users.

Prepare a local module

First determine the module you wish to add as a local module:

  • If you are adding your own custom module, be sure that you have followed the steps to create your own module to code and compile your module and generate an executable.
  • If you are using a pre-built module, make sure you have installed the module and determined the filename of the module’s executable.

Then, ensure that viam-server is able to find and run the executable:

  • Ensure that the module executable is saved to a location on the filesystem of your machine that viam-server can access. For example, if you are running viam-server on an Raspberry Pi, you must save the module executable on the Pi’s filesystem.

  • Ensure that this file is executable (runnable) with the following command:

    sudo chmod a+rx <path-to-your-module-executable>
    

See the instructions to compile your module into an executable for more information.

Add a local module

To add a local module on your machine, first add its module, then the component or service it implements:

  1. Navigate to the CONFIGURE tab of your machine’s page in the Viam app.

  2. Click the + (Create) icon next to your machine part in the left-hand menu and select Local module, then Local module.

  3. Enter a Name for this instance of your module.

  4. Enter the module’s executable path. This path must be the absolute path to the executable on your machine’s filesystem.

  5. Then, click the Create button, and click Save in the upper right corner to save your config.

    The add a local module pane with name 'my-csi-cam' and executable path '/usr/local/bin/viam-csi'

    This example shows the configuration for adding a CSI camera as a local module.

  6. Now, stay on the CONFIGURE tab of your machine’s page on the Viam app.

    • Click the + (Create) icon next to your machine part in the left-hand menu and select Local module.
    • Then, select Local component or Local service.
  7. On the Create menu for a Local component or Local service:

    • Select the type of modular resource provided by your module, such as a camera, from the dropdown menu.

    • Enter the model namespace triplet of your modular resource’s model. If you are adding a pre-built modular resource, the model triplet should be provided for you in the module’s documentation.

    • Enter a name for this instance of your modular resource. This name must be different from the module name.

      The add a component model showing the create a module step for an intel realsense module
  8. Click Create to create the modular resource provided by the local module.

Once you’ve added your local module using steps 1-5, you can repeat steps 6-8 to add as many additional instances of your modular resource as you need.

Edit the configuration of a local module

Once you have added a modular resource to your machine, you can view and edit the underlying module.

Navigate to the CONFIGURE tab of your machine’s page in the Viam app. Local modules you have added to your machine are identifiable by name. Locate a module’s card in the part-resource hierarchy and click on it to expand.

The following properties are available for modules:

NameTypeInclusionDescription
namestringRequiredName of the module you are registering.
executable_pathstringRequiredThe absolute path to the executable on your machine’s filesystem.
typestringRequiredEither registry or local.

Edit these properties in your module’s JSON configuration:

The edit a local module pane with an example name and executable path
{
  "modules": [
    {
      "name": "<your-module-name>",
      "executable_path": "<path-on-your-filesystem-to/your-module-directory>/<your_executable.sh>",
      "type": "local"
    }
  ]
}

Add a local modular resource

Once you have added a local module to your machine, you can add any number of the resources provided by that module to your machine by adding new components or services that use your modular resource’s model.

The following properties are available for modular resources:

NameTypeInclusionDescription
namespacestringRequiredThe namespace of the API (the first part of the API namespace triplet). See Valid APIs to implement in your model.
typestringRequiredThe subtype of the API (the third part of the API namespace triplet). See Valid APIs to implement in your model.
namestringRequiredA custom name for this instance of your modular resource.
modelstringRequiredThe full model namespace triplet of the modular resource’s model.
depends_onarrayOptionalThe name of components you want to confirm are available on your machine alongside your modular resource. Often a board. Unnecessary if you coded implicit dependencies.

All standard properties for configuration, such as attributes and depends_on, are also supported for modular resources. The attributes available vary depending on your implementation.

{
  "components": [
    {
      "namespace": "<your-module-namespace>",
      "type": "<your-resource-subtype>",
      "model": "<namespace>:<repo-name>:<name>",
      "name": "<your-model-instance-name>",
      "attributes": {},
      "depends_on": []
    }
  ],
  "modules": [ ... ] // < INSERT YOUR MODULE CONFIGURATION >
}

The following is an example configuration for a base modular resource implementation. The configuration adds acme:demo:mybase as a modular resource from the module my_base. The custom model is configured as a component with the name “my-custom-base-1”. You can send commands to the base according to the Viam base API:

{
  "components": [
    {
      "type": "board",
      "name": "main-board",
      "model": "pi"
    },
    {
      "type": "base",
      "name": "my-custom-base-1",
      "model": "acme:demo:mybase",
      "namespace": "rdk",
      "attributes": {},
      "depends_on": ["main-board"]
    }
  ],
  "modules": [
    {
      "name": "my-custom-base",
      "executable_path": "/home/my_username/my_base/run.sh"
    }
  ]
}

Next steps

Now that you’ve configured a modular resource, test it with the CONTROL tab and program it with the Viam SDKs.

You can also check out these tutorials that configure and use modular resources: