# Servo API

The servo API allows you to give commands to your [servo components](https://docs.viam.com/reference/components/servo/) for controlling the angular position of a hobby servo precisely or getting its current status.

Industrial servos should use the [motor API](https://docs.viam.com/reference/apis/components/motor/) which provides more features than the servo API.

The servo component supports the following methods:

| Method Name | Description | `viam-micro-server` Support |
| --- | --- | --- |
| [`Move`](https://docs.viam.com/reference/apis/components/servo/#move) | Move the servo to the desired angle in degrees. |  |
| [`GetPosition`](https://docs.viam.com/reference/apis/components/servo/#getposition) | Get the current set angle of the servo in degrees. |  |
| [`IsMoving`](https://docs.viam.com/reference/apis/components/servo/#ismoving) | Returns whether the servo is actively moving (or attempting to move) under its own power. |  |
| [`Stop`](https://docs.viam.com/reference/apis/components/servo/#stop) | Stop the servo from moving. |  |
| [`GetGeometries`](https://docs.viam.com/reference/apis/components/servo/#getgeometries) | Get all the geometries associated with the servo in its current configuration, in the frame of the servo. |  |
| [`Reconfigure`](https://docs.viam.com/reference/apis/components/servo/#reconfigure) | Reconfigure this resource. |  |
| [`DoCommand`](https://docs.viam.com/reference/apis/components/servo/#docommand) | Execute model-specific commands that are not otherwise defined by the component API. |  |
| [`GetResourceName`](https://docs.viam.com/reference/apis/components/servo/#getresourcename) | Get the `ResourceName` for this servo. |  |
| [`Close`](https://docs.viam.com/reference/apis/components/servo/#close) | Safely shut down the resource and prevent further use. |  |

## API

### Move

Move the servo to the desired angle in degrees.

#### Stability Notice

Support for continuous servos with the GPIO servo model is experimental. Stability is not guaranteed. Breaking changes are likely to occur, and occur often.

If you are using a continuous rotation servo, you can use the `Move` command, but instead of moving to a given position, the servo will start moving at a set speed.

The speed will be related to the “angle” you pass in as a linear approximation. 90 degrees represents stop, 91 to 180 represents counter-clockwise rotation from slowest to fastest, and 89 to 1 represents clockwise from slowest to fastest. It is recommended that you test your servo to determine the desired speed.

Supported by `viam-micro-server`.

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

**Parameters:**

- `angle` ( [int](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex)) (required): The desired angle of the servo in degrees.
- `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:**

- None.

**Example:**

```python

```

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

### GetPosition

Get the current set angle of the servo in degrees. Supported by `viam-micro-server`.

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

**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:**

- ( [int](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex)): : The current angle of the servo in degrees.

**Example:**

```python

```

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

### IsMoving

Returns whether the servo is actively moving (or attempting to move) under its own power.

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

**Parameters:**

- `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:**

- ( [bool](https://docs.python.org/3/library/stdtypes.html#boolean-type-bool)): : Whether the servo is moving.

**Example:**

```python

```

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

### Stop

Stop the servo from moving. Supported by `viam-micro-server`.

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

**Parameters:**

**Returns:**

- None.

**Example:**

```python

```

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

### GetGeometries

Get all the geometries associated with the servo in its current configuration, in the [frame](https://docs.viam.com/reference/services/frame-system/) of the servo. 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/servo/#tabset-referenceapiscomponentsservo-5-0)

**Parameters:**

**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

```

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

### Reconfigure

Reconfigure this resource. Reconfigure must reconfigure the resource atomically and in place.

- [Go](https://docs.viam.com/reference/apis/components/servo/#tabset-referenceapiscomponentsservo-6-0)

**Parameters:**

- `ctx` [(Context)](https://pkg.go.dev/context#Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
- `deps` [(Dependencies)](https://pkg.go.dev/go.viam.com/rdk/resource#Dependencies): The resource dependencies.
- `conf` [(Config)](https://pkg.go.dev/go.viam.com/rdk/resource#Config): The resource configuration.

**Returns:**

- [(error)](https://pkg.go.dev/builtin#error): An error, if one occurred.

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

### DoCommand

Execute model-specific commands that are not otherwise defined by the component API. Most models do not implement `DoCommand`. Any available model-specific commands should be covered in the model’s documentation. If you are implementing your own servo 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/).

- [Python](https://docs.viam.com/reference/apis/components/servo/#tabset-referenceapiscomponentsservo-7-0)
- [Go](https://docs.viam.com/reference/apis/components/servo/#tabset-referenceapiscomponentsservo-7-1)
- [TypeScript](https://docs.viam.com/reference/apis/components/servo/#tabset-referenceapiscomponentsservo-7-2)
- [Flutter](https://docs.viam.com/reference/apis/components/servo/#tabset-referenceapiscomponentsservo-7-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), viam.utils.ValueTypes]): : Result of the executed command.

**Raises:**

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

**Example:**

```python

```

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

### GetResourceName

Get the `ResourceName` for this servo.

- [Python](https://docs.viam.com/reference/apis/components/servo/#tabset-referenceapiscomponentsservo-8-0)
- [Go](https://docs.viam.com/reference/apis/components/servo/#tabset-referenceapiscomponentsservo-8-1)
- [TypeScript](https://docs.viam.com/reference/apis/components/servo/#tabset-referenceapiscomponentsservo-8-2)
- [Flutter](https://docs.viam.com/reference/apis/components/servo/#tabset-referenceapiscomponentsservo-8-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

```

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

### Close

Safely shut down the resource and prevent further use.

- [Python](https://docs.viam.com/reference/apis/components/servo/#tabset-referenceapiscomponentsservo-9-0)
- [Go](https://docs.viam.com/reference/apis/components/servo/#tabset-referenceapiscomponentsservo-9-1)

**Parameters:**

- None.

**Returns:**

- None.

**Example:**

```python

```

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