Skip to content

Commit c06f0a8

Browse files
authored
DOCS-3334: Add back advanced modular resources, and add aliases (#3813)
1 parent 480714b commit c06f0a8

File tree

11 files changed

+375
-7
lines changed

11 files changed

+375
-7
lines changed

docs/data-ai/ai/deploy.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ description: "The Machine Learning (ML) model service allows you to deploy machi
99
aliases:
1010
- /how-tos/train-deploy-ml/
1111
- /services/ml/
12+
- /registry/ml/
13+
- /services/ml/upload-model/
14+
- /services/ml/edit/
15+
- /ml/edit/
16+
- /manage/data/upload-model/
17+
- /manage/ml/upload-model/
18+
- /ml/upload-model/
19+
- /services/ml/ml-models/
1220
---
1321

1422
The Machine Learning (ML) model service allows you to deploy [machine learning models](/data-ai/ai/deploy/#deploy-your-ml-model) to your machine.
@@ -66,5 +74,5 @@ For other use cases, consider [creating custom functionality with a module](/ope
6674

6775
{{< alert title="Add support for other models" color="tip" >}}
6876
ML models must be designed in particular shapes to work with the `mlmodel` [classification](/operate/reference/services/vision/mlmodel/) or [detection](/operate/reference/services/vision/mlmodel/) model of Viam's [vision service](/operate/reference/services/vision/).
69-
See [ML Model Design](/registry/advanced/mlmodel-design/) to design a modular ML model service with models that work with vision.
77+
See [ML Model Design](/operate/reference/advanced-modules/mlmodel-design/) to design a modular ML model service with models that work with vision.
7078
{{< /alert >}}

docs/dev/reference/glossary/part.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Part
33
id: part
4-
full_link: /architecture/parts/
4+
full_link: /operate/reference/architecture/parts/
55
short_description: A single-board computer, desktop, laptop, or other computer running viam-server, the hardware components attached to it, and any services or other resources running on it.
66
---
77

docs/dev/reference/glossary/resource.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ Resources are individual, addressable elements of a machine.
1717
Each part has local resources and can also have resources from another {{< glossary_tooltip term_id="remote-part" text="remote">}} machine part.
1818
The capabilities of each resource are exposed through the part’s API.
1919

20-
Each resource on your machine implements either one of the [existing Viam APIs](/dev/reference/apis/), or a [custom interface](/registry/advanced/#new-api-subtypes).
20+
Each resource on your machine implements either one of the [existing Viam APIs](/dev/reference/apis/), or a [custom interface](/operate/reference/advanced-modules/#new-api-subtypes).

docs/dev/reference/sdks/use-extra-params.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ If passing an object of type `nil`, you must specify `nil` in the method call or
9090

9191
## Define
9292

93-
If `extra` information must be passed to a resource, it is handled within a new, _modular_ resource model's [custom API](/registry/) wrapper.
93+
If `extra` information must be passed to a resource, it is handled within a new, _modular_ resource model's [custom API](/operate/get-started/other-hardware/) wrapper.
9494

9595
{{%expand "Click for instructions on defining a custom model to use extra params" %}}
9696

docs/operate/get-started/other-hardware/cpp-module.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ If you want to write a module to add support to a new type of component or servi
7070

7171
- If you are working with a component that doesn't fit into any of the existing component APIs, you can use the [generic component](/operate/reference/components/generic/) to build your own component API.
7272
- If you are designing a service that doesn't fit into any of the existing service APIs, you can use the [generic service](/operate/reference/components/generic/) to build your own service API.
73-
- It is also possible to [define an entirely new API](/registry/advanced/create-subtype/), but this is even more advanced than using `generic`.
73+
- It is also possible to [define an entirely new API](/operate/reference/advanced-modules/create-subtype/), but this is even more advanced than using `generic`.
7474

7575
Most module use cases, however, benefit from implementing an existing API instead of `generic`.
7676
{{% /alert %}}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: "Advanced Modular Resources"
3+
linkTitle: "Advanced Modules"
4+
type: docs
5+
tags:
6+
[
7+
"server",
8+
"rdk",
9+
"extending viam",
10+
"modular resources",
11+
"components",
12+
"services",
13+
]
14+
description: "Some usage may require you to define new APIs or deploy custom components using a server on a remote part"
15+
aliases:
16+
- /program/extend/
17+
- /modular-resources/advanced/
18+
- /registry/advanced/
19+
date: "2022-01-01"
20+
# updated: "" # When the content was last entirely checked
21+
toc_hide: true
22+
---
23+
24+
Some use cases may require advanced considerations when designing or deploying modular resources.
25+
Depending on your needs, you may wish to define an entirely new API subtype, deploy a custom component using a server on a {{< glossary_tooltip term_id="remote-part" text="remote" >}} {{< glossary_tooltip term_id="part" text="part" >}}, or design a custom ML model.
26+
27+
## New API subtypes
28+
29+
The [component APIs](/dev/reference/apis/#component-apis) and [service APIs](/dev/reference/apis/#service-apis) provide a standard interface for controlling common hardware components and higher level functionality.
30+
If your use case aligns closely with an existing API, you should use that API to program your new resource.
31+
32+
If you want to use most of an existing API but need just a few other functions, you can use the `DoCommand` endpoint together with [extra parameters](/dev/reference/sdks/use-extra-params/) to add custom functionality to an existing resource {{< glossary_tooltip term_id="subtype" text="subtype" >}}.
33+
34+
Or, if your resource does not fit into an existing resource subtype, you can use one of the following:
35+
36+
- If you are working with a component that doesn't fit into any of the existing [component APIs](/dev/reference/apis/#component-apis), you can use the [generic component](/operate/reference/components/generic/) to build your own component API.
37+
- If you are designing a service that doesn't fit into any of the existing [service APIs](/dev/reference/apis/#service-apis), you can use the [generic service](/dev/reference/apis/services/generic/) to build your own service API.
38+
39+
Both generic resources use the [`DoCommand`](/dev/reference/apis/components/generic/#docommand) endpoint to enable you to make arbitrary calls as needed for your resource.
40+
41+
Alternatively, you can also [define a new resource subtype and an API for that subtype](/operate/reference/advanced-modules/create-subtype/) if none of the above options are a good fit for your use case.
42+
43+
## Custom components as remotes
44+
45+
Running {{< glossary_tooltip term_id="modular-resource" text="modular resources" >}} on the computer directly connected to your components is the preferred way of managing and controlling custom components.
46+
47+
However, if you are unable to use modular resources because you need to host `viam-server` on a non-Linux system or have an issue with compilation, you may need to [implement a custom component and register it on a server configured as a remote](/operate/reference/advanced-modules/custom-components-remotes/) on your machine.
48+
49+
## Design a custom ML model
50+
51+
When working with the [ML model service](/dev/reference/apis/services/ml/), you can deploy an [existing model](/data-ai/ai/deploy/) or [train your own model](/data-ai/ai/train/).
52+
53+
However, if you are writing your own {{< glossary_tooltip term_id="module" text="module" >}} that uses the ML model service together with the [vision service](/dev/reference/apis/services/vision/), you can also [design your own ML model](/operate/reference/advanced-modules/mlmodel-design/) to better match your specific use case.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
title: "Define a New Resource Subtype"
3+
linkTitle: "New API Subtype"
4+
weight: 30
5+
type: "docs"
6+
tags: ["rdk", "extending viam", "modular resources", "API"]
7+
description: "Define a custom API for a resource that does not fit into existing component or service subtypes."
8+
no_list: true
9+
aliases:
10+
- /extend/modular-resources/create/create-subtype/
11+
- /modular-resources/advanced/create-subtype/
12+
- /registry/advanced/create-subtype/
13+
date: "2022-01-01"
14+
# updated: "" # When the content was last entirely checked
15+
---
16+
17+
You can define a new, custom {{< glossary_tooltip term_id="resource" text="resource" >}} _{{< glossary_tooltip term_id="subtype" text="subtype" >}}_ API if:
18+
19+
- You have a {{% glossary_tooltip term_id="resource" text="resource" %}} that does not fit into any of the existing {{< glossary_tooltip term_id="component" text="component" >}} or {{< glossary_tooltip term_id="service" text="service" >}} subtypes.
20+
- You have a resource that could fit into an existing subtype, but you want to define an API with different methods and messages than the ones in the existing [APIs](/dev/reference/apis/) for that subtype.
21+
22+
{{% alert title="Tip" color="tip" %}}
23+
24+
If you want to use most of an existing API but need just a few other functions, try using the `DoCommand` endpoint and [extra parameters](/dev/reference/sdks/use-extra-params/) to add custom functionality to an existing subtype.
25+
For example, if you have a [sensor](/operate/reference/components/sensor/) and you want to define a `Calibrate` method, you can use `DoCommand`.
26+
27+
If your use case uses only `DoCommand` and no other API methods, you can define a new model of [generic component](/operate/reference/components/generic/) or [generic service](/operate/reference/services/generic/).
28+
29+
{{% /alert %}}
30+
31+
## Define your new resource API
32+
33+
Viam uses [protocol buffers](https://protobuf.dev/) for API definition.
34+
35+
To define a new subtype, you need to define the methods and messages of the new API in [protobuf](https://github.com/protocolbuffers/protobuf), write code in Python or Go to implement the higher level server and client functions required, and generate all necessary [protobuf module files](https://buf.build/docs/generate/usage/).
36+
The following steps guide you through this process in more detail:
37+
38+
1. Decide whether your custom subtype is a {{< glossary_tooltip term_id="component" text="component" >}} or a {{< glossary_tooltip term_id="service" text="service" >}}.
39+
If it provides an interface to control hardware, it is a component.
40+
If it provides higher-level functionality, it is a service.
41+
1. Choose a name for your subtype.
42+
For example, `gizmo`.
43+
44+
Determine a valid {{< glossary_tooltip term_id="api-namespace-triplet" text="API namespace triplet" >}} based on your subtype name.
45+
You can figure out the {{< glossary_tooltip term_id="model-namespace-triplet" text="model namespace triplet" >}} later when you [create a model that implements your custom API](/operate/get-started/other-hardware/).
46+
47+
{{< expand "API namespace triplet and model namespace triplet example" >}}
48+
49+
The `viam-labs:audioout:pygame` model uses the repository name [audioout](https://github.com/viam-labs/audioout).
50+
It implements the custom API `viam-labs:service:audioout`:
51+
52+
```json
53+
{
54+
"api": "viam-labs:service:audioout",
55+
"model": "viam-labs:audioout:pygame"
56+
}
57+
```
58+
59+
For your custom API, your API namespace triplet might be `your-org-namespace:component:gizmo` where `your-org-namespace` is your organization namespace, found in your org settings page in the Viam app.
60+
61+
{{< /expand >}}
62+
63+
1. Create a directory for your module.
64+
Within that, create a directory called <file>src</file>.
65+
66+
{{% alert title="Tip" color="tip" %}}
67+
68+
If you are writing your module using Python, you can use this [module generator tool](https://github.com/viam-labs/generator-viam-module) to generate stub files for the new API as well as a new {{< glossary_tooltip term_id="module" text="module" >}} that implements the new API.
69+
70+
{{% /alert %}}
71+
72+
1. Define your new API:
73+
74+
- [Write the proto](https://protobuf.dev/programming-guides/proto3/) methods in a `<subtype name>.proto` file inside your <file>src/proto</file> directory.
75+
For reference:
76+
- [Example modular component proto file](https://github.com/viamrobotics/viam-python-sdk/blob/main/examples/complex_module/src/proto/gizmo.proto)
77+
- [Example modular service proto file](https://github.com/viam-labs/speech-service-api/blob/main/src/proto/speech.proto)
78+
- [Built-in Viam resource proto files](https://github.com/viamrobotics/api/tree/main/proto/viam)
79+
- And define the proto methods in a protobuf-supported language such as Python or Go in a file called `api.py` or `api.go`, respectively.
80+
- [Example component in Python](https://github.com/viamrobotics/viam-python-sdk/blob/main/examples/complex_module/src/gizmo/api.py)
81+
- [Example service in Python](https://github.com/viam-labs/speech-service-api/blob/main/src/speech_service_api/api.py)
82+
83+
1. In the root directory of your module, you need to generate some configuration files.
84+
You will typically need the following three files for most modules, though different files are required for some advanced use cases.
85+
See the [Buf documentation](https://buf.build/docs/generate/usage/) for instructions.
86+
87+
- [<file>buf.yaml</file>](https://buf.build/docs/configuration/v1/buf-gen-yaml/)
88+
- [<file>buf.gen.yaml</file>](https://buf.build/docs/configuration/v1/buf-gen-yaml/)
89+
- [<file>buf.lock</file>](https://buf.build/docs/configuration/v1/buf-lock/)
90+
91+
1. In the <file>/src/</file> directory of your module, use the protobuf compiler to [generate](https://buf.build/docs/tutorials/getting-started-with-buf-cli/#generate-code) all other necessary protocol buffer code, based on the `<subtype name>.proto` file you wrote.
92+
93+
- [Example generated files for a Python-based service](https://github.com/viam-labs/speech-service-api/tree/main/src/proto).
94+
The `buf.` files were generated.
95+
The <file>speech.proto</file> was manually written.
96+
97+
## Next steps
98+
99+
{{< cards >}}
100+
{{% manualcard link="/operate/get-started/other-hardware/" %}}
101+
102+
<h4>Implement your API</h4>
103+
104+
Now that your resource API is defined, create a new model that implements your new API.
105+
106+
{{% /manualcard %}}
107+
{{< /cards >}}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: "Add Custom Components as Remote Machine Parts"
3+
linkTitle: "Custom Components as Remote Parts"
4+
weight: 99
5+
type: "docs"
6+
tags: ["server", "sdk"]
7+
aliases:
8+
- /program/extend/sdk-as-server/
9+
- /program/extend/custom-components-remotes/
10+
- /extend/custom-components-remotes/
11+
- /modular-resources/advanced/custom-components-remotes/
12+
- /registry/advanced/custom-components-remotes/
13+
description: "If you are unable to use modular resources, you can implement custom components and register them on a server configured as a remote of your machine."
14+
date: "2022-01-01"
15+
# updated: "" # When the content was last entirely checked
16+
---
17+
18+
Running {{< glossary_tooltip term_id="modular-resource" text="modular resources" >}} on the computer directly connected to your components is the preferred way of managing and controlling custom components.
19+
20+
However, if you are unable to use [modular resources](/operate/get-started/other-hardware/) because you need to host `viam-server` on a non-Linux system or have an issue with compilation, you can use a [Viam SDK](/dev/reference/sdks/) to code a custom resource implementation, host it on a server, and add it as a [remote part](/operate/reference/architecture/parts/) of your machine.
21+
22+
Once you have coded your custom component and configured the remote servers, you can control and monitor your component with the Viam SDKs, like any other component.
23+
24+
To show how to create a custom resource, the following example creates an arm as a custom component and registers the new arm model with a Viam SDK.
25+
Then you can control it as part of your machine with the same [API methods](/dev/reference/apis/components/arm/#api) available for [arm models built into the RDK](/operate/reference/components/arm/#configuration).
26+
27+
## Instructions
28+
29+
To add a custom resource as a [remote part](/operate/reference/architecture/parts/):
30+
31+
{{< tabs >}}
32+
{{% tab name="Go" %}}
33+
34+
1. Code a new model of a built-in resource type.
35+
You can do this by creating a new interface that implements required methods.
36+
The new model must implement any functions of the built-in resource type marked as required in its [RDK API definition](/dev/reference/apis/).
37+
2. Register the custom component on a new gRPC server instance and start the server.
38+
3. Add the server as a [remote part](/operate/reference/architecture/parts/) of your machine.
39+
4. (Optional) [Configure a process](/manage/reference/processes/) to launch this remote server to ensure the remote server is always running alongside the rest of your machine.
40+
41+
Each remote server can host one or many custom components.
42+
43+
{{% /tab %}}
44+
{{% tab name="Python" %}}
45+
46+
{{< alert title="Tip" color="tip" >}}
47+
For more detailed instructions, see the full example in the [Python SDK documentation](https://python.viam.dev/examples/example.html#subclass-a-component).
48+
{{< /alert >}}
49+
50+
1. Code a new model of a built-in resource type.
51+
You can do this by subclassing a built in resource type like `sensor` or `arm`.
52+
The new model must implement any methods of the built-in resource type marked as required in its [RDK API definition](/dev/reference/apis/).
53+
1. Register the custom component on a new gRPC server instance and start the server.
54+
You can do this with the [`viam.rpc` library](https://python.viam.dev/autoapi/viam/rpc/index.html) by creating a new `rpc.server.Server` instance.
55+
1. Add the server as a [remote part](/operate/reference/architecture/parts/) of your machine.
56+
1. (Optional) [Configure a process](/manage/reference/processes/) to launch this remote server to ensure the remote server is always running alongside the rest of your machine.
57+
58+
Each remote server can host one or many custom components.
59+
60+
{{% /tab %}}
61+
{{% /tabs %}}
62+
63+
{{% alert title="Important" color="note" %}}
64+
65+
You must define all methods belonging to a built-in resource type when defining a new model.
66+
Otherwise, the class will not instantiate.
67+
68+
- If you are using the Python SDK, raise an `NotImplementedError()` in the body of functions you do not want to implement or put `pass`.
69+
- If you are using the Go SDK, return `errUnimplemented`.
70+
- Additionally, return any values designated in the function's return signature, typed correctly.
71+
72+
{{% /alert %}}

0 commit comments

Comments
 (0)