Previous
Navigation
The generic service API allows you to give commands to your generic services for running model-specific commands using DoCommand.
The generic service supports the following methods:
| Method Name | Description |
|---|---|
DoCommand | Execute model-specific commands. |
GetResourceName | Get the ResourceName for this instance of the generic service. |
Close | Safely shut down the resource and prevent further use. |
Execute model-specific commands.
If you are implementing your own generic service and want to add features that have no corresponding built-in API method, you can implement them with DoCommand.
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:
Example:
service = Generic.from_robot(robot=machine, "my_generic_service_svc")
my_command = {
"cmnd": "dosomething",
"someparameter": 52
}
await service.do_command(command=my_command)
For more information, see the Python SDK Docs.
Parameters:
ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.cmd (map[string]interface{}): The command to execute.Returns:
Example:
myGenericService, err := generic.FromRobot(machine, "my_generic_service")
command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myGenericService.DoCommand(context.Background(), command)
For more information, see the Go SDK Docs.
Parameters:
command (Struct) (required): The command to execute.callOptions (CallOptions) (optional)Returns:
Example:
import { Struct } from '@viamrobotics/sdk';
const result = await resource.doCommand(
Struct.fromJson({
myCommand: { key: 'value' },
})
);
For more information, see the TypeScript SDK Docs.
Get the ResourceName for this instance of the generic service.
Parameters:
name (str) (required): The name of the Resource.Returns:
Example:
my_generic_service_name = Generic.get_resource_name("my_generic_service")
For more information, see the Python SDK Docs.
Parameters:
Returns:
Example:
myGenericService, err := generic.FromRobot(machine, "my_generic_service")
err = myGenericService.Name()
For more information, see the Go SDK Docs.
Parameters:
Returns:
Example:
generic_service.name
For more information, see the TypeScript SDK Docs.
Safely shut down the resource and prevent further use.
Parameters:
Returns:
Example:
my_generic_service = Generic.from_robot(robot=machine, name="my_generic_service")
await my_generic_service.close()
For more information, see the Python SDK Docs.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!