Encoder API | Component APIs
Encoder API
The encoder API allows you to give commands to your encoder components for getting the position of a motor or a joint in ticks or degrees.
The encoder component supports the following methods:
| Method Name | Description | viam-micro-server Support |
|---|---|---|
GetPosition |
Get the current position of the encoder in ticks or degrees. | |
ResetPosition |
Set the current position of the encoder to be the new zero position. | |
GetProperties |
Get a list of all the position types that are supported by a given encoder. | |
GetGeometries |
Get all the geometries associated with the encoder in its current configuration, in the frame of the encoder. | |
Reconfigure |
Reconfigure this resource. | |
DoCommand |
Execute model-specific commands that are not otherwise defined by the component API. | |
GetResourceName |
Get the ResourceName for this encoder. |
|
Close |
Safely shut down the resource and prevent further use. |
API
GetPosition
Get the current position of the encoder in ticks or degrees.
Relative encoders return ticks since last zeroing.
Absolute encoders return degrees.
Supported by viam-micro-server.
Parameters:
position_type( viam.proto.component.encoder.PositionType.ValueType) (optional): The desired output type of the position.extra(Mapping[ str, Any]) (optional): Extra options to pass to the underlying RPC call.timeout( float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- (Tuple[ float, PositionType.ValueType]): : A tuple containing two values; the first [0] the position of the encoder which can either be ticks since last zeroing for a relative encoder or degrees for an absolute encoder, and the second [1] the type of position the encoder returns (ticks or degrees).
Example:
For more information, see the Python SDK Docs.
ResetPosition
Set the current position of the encoder to be the new zero position.
Supported by viam-micro-server.
Parameters:
extra(Mapping[ str, Any]) (optional): Extra options to pass to the underlying RPC call.timeout( float) (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:
For more information, see the Python SDK Docs.
GetProperties
Get a list of all the position types that are supported by a given encoder.
Supported by viam-micro-server.
Parameters:
Returns:
- ( viam.components.encoder.encoder.Encoder.Properties): : Map of position types to supported status.
Example:
For more information, see the Python SDK Docs.
GetGeometries
Get all the geometries associated with the encoder in its current configuration, in the frame of the encoder. The motion and navigation services use the relative position of inherent geometries to configured geometries representing obstacles for collision detection and obstacle avoidance while motion planning.
Parameters:
Returns:
- ( List[viam.proto.common.Geometry]): : The geometries associated with the Component.
Example:
For more information, see the Python SDK Docs.
Reconfigure
Reconfigure this resource. Reconfigure must reconfigure the resource atomically and in place.
Parameters:
ctx(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.deps(Dependencies): The resource dependencies.conf(Config): The resource configuration.
Returns:
- (error): An error, if one occurred.
For more information, see the Go SDK Docs.
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 encoder as a modular resource and want to add features that have no corresponding built-in API method, you can implement them with DoCommand.
Supported by viam-micro-server.
Parameters:
command(Mapping[ str, ValueTypes]) (required): The command to execute.timeout( float) (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, viam.utils.ValueTypes]): : Result of the executed command.
Raises:
- (NotImplementedError): Raised if the Resource does not support arbitrary commands.
Example:
For more information, see the Python SDK Docs.
GetResourceName
Get the ResourceName for this encoder.
Parameters:
name( str) (required): The name of the Resource.
Returns:
- ( viam.proto.common.ResourceName): : The ResourceName of this Resource.
Example:
For more information, see the Python SDK Docs.
Close
Safely shut down the resource and prevent further use.
Parameters:
- None.
Returns:
- None.
Example: