Skip to content

Latest commit

 

History

History
216 lines (140 loc) · 6.79 KB

_index.md

File metadata and controls

216 lines (140 loc) · 6.79 KB
title linkTitle childTitleEndOverwrite weight type description tags icon images draft no_list modulescript
Template Component
Template
Template Component
10
docs
A NAME is a ... description of what the component is.
camera
components
true
/icons/components.png
true
true
true

{{}}

Brief description of the component and what you can do with it.

Use cases (optional):

  • A brief description of one sample use case.
  • ...

Most machines with a COMPONENT need at least the following hardware (optional):

  • Board
  • ...

Related services

Add services commonly used with the component.

{{< cards >}} {{< relatedcard link="/data/" >}} {{< relatedcard link="/mobility/frame-system/" >}} {{< /cards >}}

Supported models

To use your COMPONENT with Viam, check whether one of the following built-in models or modular resources supports your COMPONENT.

Built-in models

For configuration information, click on the model name:

Model Description
model1 An XYZ unit made by Some Company(INSERT LINK AS APPLICABLE)
model2 An ABCDE unit made by Some Other Company(INSERT LINK AS APPLICABLE)

Modular resources

{{}}

{{< readfile "/static/include/create-your-own-mr.md" >}}

Control your board with Viam's client SDK libraries

To get started using Viam's SDKs to connect to and control your machine, go to your machine's page on the Viam app, navigate to the CONNECT tab's Code sample page, select your preferred programming language, and copy the sample code generated.

{{% snippet "show-secret.md" %}}

When executed, this sample code will create a connection to your machine as a client. Then control your machine programmatically by getting your COMPONENT component from the machine with FromRobot and adding API method calls, as shown in the following examples.

These examples assume you have a board called "my_board" configured as a component of your machine. If your board has a different name, change the name in the code.

Be sure to import the COMPONENT package for the SDK you are using:

{{< tabs >}} {{% tab name="Python" %}}

from viam.components.componentname import ComponentName

{{% /tab %}} {{% tab name="Go" %}}

import (
  "go.viam.com/rdk/components/componentname"
)

{{% /tab %}} {{< /tabs >}}

API

The COMPONENT component supports the following methods:

Writing Instructions: Use the method names in the protobuf, not the Python or Go-specific method names. Use an included snippet so you can add it to /program/apis/.

{{< readfile "/static/include/components/apis/component.md" >}}

GetReadings

Get the measurements or readings that this sensor provides.

{{< tabs >}} {{% tab name="Python" %}}

Parameters:

  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

For more information, see the Python SDK Docs (INSERT RELEVANT LINK).

my_sensor = Sensor.from_robot(robot=robot, name='my_sensor')

# Get the readings provided by the sensor.
readings = await my_sensor.get_readings()

{{% /tab %}} {{% tab name="Go" %}}

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

For more information, see the Go SDK Docs.

mySensor, err := sensor.FromRobot(robot, "my_sensor")
if err != nil {
  logger.Fatalf("cannot get sensor: %v", err)
}

readings, err := mySensor.Readings(context.Background(), nil)

{{% /tab %}} {{< /tabs >}}

MethodName2

1-2 sentence description of what the method does.

{{< tabs >}} {{% tab name="Python" %}}

Parameters:

  • extra (Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.
  • timeout (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • None

For more information, see the Python SDK Docs (INSERT RELEVANT LINK).

my_sensor = Sensor.from_robot(robot=robot, name='my_sensor')

# Do the thing that the method does.
await my_sensor.method_name_two()

{{% /tab %}} {{% tab name="Go" %}}

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

mySensor, err := sensor.FromRobot(robot, "my_sensor")
if err != nil {
  logger.Fatalf("cannot get sensor: %v", err)
}

err := mySensor.MethodNameTwo(context.Background(), nil)

{{% /tab %}} {{< /tabs >}}

Troubleshooting

Troubleshooting information for configuration errors.

You can find additional assistance in the Troubleshooting section.

{{< snippet "social.md" >}}

Next steps

{{< cards >}} {{< /cards >}}