# Control your generic component with the generic API

The generic API allows you to give commands to your [generic components](https://docs.viam.com/reference/components/generic/) for running model-specific commands using [`DoCommand`](https://docs.viam.com/reference/apis/components/generic/#docommand).

#### Example usage

See [Deploy control logic](https://docs.viam.com/build-modules/write-a-logic-module/) for an example of how to use the generic component API, including how to call `DoCommand()` from the SDKs or the web UI.

The generic component supports the following method:

| Method Name | Description | `viam-micro-server` Support |
| --- | --- | --- |
| [`GetGeometries`](https://docs.viam.com/reference/apis/components/generic/#getgeometries) | Get all the geometries associated with the generic component in its current configuration, in the frame of the generic component. |  |
| [`DoCommand`](https://docs.viam.com/reference/apis/components/generic/#docommand) | Execute model-specific commands. |  |
| [`GetResourceName`](https://docs.viam.com/reference/apis/components/generic/#getresourcename) | Get the `ResourceName` for this generic component. |  |
| [`Close`](https://docs.viam.com/reference/apis/components/generic/#close) | Safely shut down the resource and prevent further use. |  |

## API

### GetGeometries

Get all the geometries associated with the generic component in its current configuration, in the [frame](https://docs.viam.com/reference/services/frame-system/) of the generic component.  
The [motion](https://docs.viam.com/reference/services/motion/) and [navigation](https://docs.viam.com/reference/services/navigation/) services use the relative position of inherent geometries to configured geometries representing obstacles for collision detection and obstacle avoidance while motion planning.

- [Python](https://docs.viam.com/reference/apis/components/generic/#tabset-referenceapiscomponentsgeneric-1-0)
- [Go](https://docs.viam.com/reference/apis/components/generic/#tabset-referenceapiscomponentsgeneric-1-1)
- [TypeScript](https://docs.viam.com/reference/apis/components/generic/#tabset-referenceapiscomponentsgeneric-1-2)

**Parameters:**

- `extra` (Mapping[ [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str), Any]) (optional): Extra options to pass to the underlying RPC call.  
- `timeout` ( [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex)) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

**Returns:**

- ( [List[viam.proto.common.Geometry]](https://python.viam.dev/autoapi/viam/proto/common/index.html#viam.proto.common.Geometry)): : The geometries associated with the Component.

**Example:**

```python

```

Copy

For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/components/generic/client/index.html#viam.components.generic.client.GenericClient.get_geometries).

**Parameters:**

- `ctx` [(Context)](https://pkg.go.dev/context#Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.  
- `extra` [(map[string]interface{})](https://go.dev/blog/maps): Extra options to pass to the underlying RPC call.

**Returns:**

- [([]spatialmath.Geometry)](https://pkg.go.dev/go.viam.com/rdk/spatialmath#Geometry): The geometries associated with this resource, in any order.  
- [(error)](https://pkg.go.dev/builtin#error): An error, if one occurred.

**Example:**

```go

```

Copy

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Shaped).

**Parameters:**

- `extra` (None) (optional)  
- `callOptions` (CallOptions) (optional)

**Returns:**

- (Promise< [commonApi](https://ts.viam.dev/modules/commonApi.html). [Geometry](https://ts.viam.dev/classes/commonApi.Geometry.html)[]>

**Example:**

```ts

```

Copy

For more information, see the [TypeScript SDK Docs](https://ts.viam.dev/classes/GenericComponentClient.html#getgeometries).

### DoCommand

Execute model-specific commands.  
If you are implementing your own generic component and want to add features that have no corresponding built-in API method, you can implement them with [`DoCommand`](https://docs.viam.com/reference/sdks/docommand/).  
Supported by `viam-micro-server`.

- [Python](https://docs.viam.com/reference/apis/components/generic/#tabset-referenceapiscomponentsgeneric-2-0)
- [Go](https://docs.viam.com/reference/apis/components/generic/#tabset-referenceapiscomponentsgeneric-2-1)
- [TypeScript](https://docs.viam.com/reference/apis/components/generic/#tabset-referenceapiscomponentsgeneric-2-2)
- [Flutter](https://docs.viam.com/reference/apis/components/generic/#tabset-referenceapiscomponentsgeneric-2-3)

**Parameters:**

- `command` (Mapping[ [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str), ValueTypes]) (required): The command to execute.  
- `timeout` ( [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex)) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

**Returns:**

- (Mapping[ [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str), Any]): : Result of the executed command.

**Raises:**

- (NotImplementedError): Raised if the Resource does not support arbitrary commands.

**Example:**

```python

```

Copy

For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/components/generic/client/index.html#viam.components.generic.client.GenericClient.do_command).

**Parameters:**

- `ctx` [(Context)](https://pkg.go.dev/context#Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.  
- `cmd` [(map[string]interface{})](https://go.dev/blog/maps): The command to execute.

**Returns:**

- [(map[string]interface{})](https://pkg.go.dev/builtin#string): The command response.  
- [(error)](https://pkg.go.dev/builtin#error): An error, if one occurred.

**Example:**

```go

```

Copy

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Resource).

**Parameters:**

- `command` ( [Struct](https://ts.viam.dev/classes/Struct.html)) (required): The command to execute. Accepts either a [Struct](https://ts.viam.dev/classes/Struct.html) or a plain object, which will be converted automatically.  
- `callOptions` (CallOptions) (optional)

**Returns:**

- (Promise< [JsonValue](https://ts.viam.dev/types/JsonValue.html) >)

**Example:**

```ts

```

Copy

For more information, see the [TypeScript SDK Docs](https://ts.viam.dev/classes/GenericComponentClient.html#docommand).

**Parameters:**

- `command` [Map](https://api.flutter.dev/flutter/dart-core/Map-class.html) < [String](https://api.flutter.dev/flutter/dart-core/String-class.html), dynamic> (required)

**Returns:**

- [Future](https://api.flutter.dev/flutter/dart-async/Future-class.html) < [Map](https://api.flutter.dev/flutter/dart-core/Map-class.html) < [String](https://api.flutter.dev/flutter/dart-core/String-class.html), dynamic>>

**Example:**

```dart

```

Copy

For more information, see the [Flutter SDK Docs](https://flutter.viam.dev/viam_sdk/Resource/doCommand.html).

### GetResourceName

Get the `ResourceName` for this generic component.

- [Python](https://docs.viam.com/reference/apis/components/generic/#tabset-referenceapiscomponentsgeneric-3-0)
- [Go](https://docs.viam.com/reference/apis/components/generic/#tabset-referenceapiscomponentsgeneric-3-1)
- [TypeScript](https://docs.viam.com/reference/apis/components/generic/#tabset-referenceapiscomponentsgeneric-3-2)
- [Flutter](https://docs.viam.com/reference/apis/components/generic/#tabset-referenceapiscomponentsgeneric-3-3)

**Parameters:**

- `name` ( [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str)) (required): The name of the Resource.

**Returns:**

- ( [viam.proto.common.ResourceName](https://python.viam.dev/autoapi/viam/proto/common/index.html#viam.proto.common.ResourceName)): : The ResourceName of this Resource.

**Example:**

```python

```

Copy

For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/components/generic/client/index.html#viam.components.generic.client.GenericClient.get_resource_name).

**Parameters:**

- None.

**Returns:**

- [(Name)](https://pkg.go.dev/go.viam.com/rdk@v0.89.0/resource#Name)

**Example:**

```go

```

Copy

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Resource).

**Parameters:**

- None.

**Returns:**

- (string): The name of the resource.

**Example:**

```ts

```

Copy

For more information, see the [TypeScript SDK Docs](https://ts.viam.dev/classes/GenericComponentClient.html#name).

**Parameters:**

- `name` [String](https://api.flutter.dev/flutter/dart-core/String-class.html) (required)

**Returns:**

- [ResourceName](https://flutter.viam.dev/viam_sdk/ResourceName-class.html)

**Example:**

```dart

```

Copy

For more information, see the [Flutter SDK Docs](https://flutter.viam.dev/viam_sdk/Generic/getResourceName.html).

### Close

Safely shut down the resource and prevent further use.

- [Python](https://docs.viam.com/reference/apis/components/generic/#tabset-referenceapiscomponentsgeneric-4-0)

**Parameters:**

- None.

**Returns:**

- None.

**Example:**

```python

```

Copy

For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/components/generic/client/index.html#viam.components.generic.client.GenericClient.close).
