Skip to content

Commit

Permalink
DOCS-3136: Update Automation SDK methods (#3681)
Browse files Browse the repository at this point in the history
  • Loading branch information
npentrel authored Nov 18, 2024
1 parent f25b748 commit c31ff39
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sdk_protos_map.csv
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ mlmodel,Infer,,infer,Infer,
mlmodel,Metadata,,metadata,Metadata,
## HACK: proto for DoCommand or Close (and/or inherited in Go SDK), manually mapping:
mlmodel,Reconfigure,,,Reconfigure,
mlmodel,DoCommand,,do_command,DoCommand,
mlmodel,DoCommand,,,DoCommand,
mlmodel,GetResourceName,,get_resource_name,,
mlmodel,Close,,close,Close,

Expand Down
12 changes: 4 additions & 8 deletions static/include/components/apis/generated/arm.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,13 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
**Example:**

```go {class="line-numbers linkable-line-numbers"}
// Assumes you have imported "go.viam.com/api/component/arm/v1" as `componentpb`
myArm, err := arm.FromRobot(machine, "my_arm")

// Declare an array of values with your desired rotational value for each joint on the arm.
degrees := []float64{4.0, 5.0, 6.0}
// Declare an array of values with your desired rotational value (in radians) for each joint on the arm.
inputs := referenceframe.FloatsToInputs([]float64{0, math.Pi/2, math.Pi})

// Declare a new JointPositions with these values.
jointPos := &componentpb.JointPositions{Values: degrees}

// Move each joint of the arm to the position these values specify.
err = myArm.MoveToJointPositions(context.Background(), jointPos, nil)
// Move each joint of the arm to the positions specified in the above slice
err = myArm.MoveToJointPositions(context.Background(), inputs, nil)
```

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/components/arm#Arm).
Expand Down
1 change: 1 addition & 0 deletions static/include/components/apis/generated/camera.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ import numpy as np
import open3d as o3d

my_camera = Camera.from_robot(robot=machine, name="my_camera")

data, _ = await my_camera.get_point_cloud()

# write the point cloud into a temporary file
Expand Down
27 changes: 0 additions & 27 deletions static/include/services/apis/generated/mlmodel.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,33 +135,6 @@ For built-in service models, any model-specific commands available are covered w
If you are implementing your own ML model service and add features that have no built-in API method, you can access them with `DoCommand`.

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

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

**Example:**

```python {class="line-numbers linkable-line-numbers"}
my_mlmodel_svc = MLModelClient.from_robot(robot=machine, "my_mlmodel_svc")

my_command = {
"cmnd": "dosomething",
"someparameter": 52
}

await my_mlmodel_svc.do_command(command=my_command)
```

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

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

**Parameters:**
Expand Down
80 changes: 39 additions & 41 deletions static/include/services/apis/generated/vision.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
```go {class="line-numbers linkable-line-numbers"}
myDetectorService, err := vision.FromRobot(machine, "my_detector")
if err != nil {
logger.Error(err)
return
logger.Error(err)
return
}

// Get detections from the camera output
detections, err := visService.DetectionsFromCamera(context.Background(), "cam", nil)
detections, err := myDetectorService.DetectionsFromCamera(context.Background(), "my_camera", nil)
if err != nil {
logger.Fatalf("Could not get detections: %v", err)
logger.Fatalf("Could not get detections: %v", err)
}
if len(detections) > 0 {
logger.Info(detections[0])
logger.Info(detections[0])
}
```

Expand Down Expand Up @@ -142,31 +142,29 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
**Example:**

```go {class="line-numbers linkable-line-numbers"}
// Get the stream from a camera
cam, err := camera.FromRobot(machine, "cam")
myCam, err := camera.FromRobot(machine, "my_camera")
if err != nil {
logger.Error(err)
return
logger.Error(err)
return
}
camStream, err := cam.Stream(context.Background())

// Get the stream from a camera
camStream, err := myCam.Stream(context.Background())
// Get an image from the camera stream
img, release, err := camStream.Next(context.Background())
defer release()

myDetectorService, err := vision.FromRobot(machine, "my_detector")
if err != nil {
logger.Error(err)
return
logger.Error(err)
return
}

// Get the detections from the image
detections, err := myDetectorService.Detections(context.Background(), img, nil)
if err != nil {
logger.Fatalf("Could not get detections: %v", err)
logger.Fatalf("Could not get detections: %v", err)
}
if len(detections) > 0 {
logger.Info(detections[0])
logger.Info(detections[0])
}
```

Expand Down Expand Up @@ -247,17 +245,16 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
```go {class="line-numbers linkable-line-numbers"}
myClassifierService, err := vision.FromRobot(machine, "my_classifier")
if err != nil {
logger.Error(err)
return
logger.Error(err)
return
}

// Get the 2 classifications with the highest confidence scores from the camera output
classifications, err := myClassifierService.ClassificationsFromCamera(context.Background(), "cam", 2, nil)
classifications, err := myClassifierService.ClassificationsFromCamera(context.Background(), "my_camera", 2, nil)
if err != nil {
logger.Fatalf("Could not get classifications: %v", err)
logger.Fatalf("Could not get classifications: %v", err)
}
if len(classifications) > 0 {
logger.Info(classifications[0])
logger.Info(classifications[0])
}
```

Expand Down Expand Up @@ -339,34 +336,33 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
**Example:**

```go {class="line-numbers linkable-line-numbers"}
// Get the stream from a camera
cam, err := camera.FromRobot(machine, "cam")
myCam, err := camera.FromRobot(machine, "my_camera")
if err != nil {
logger.Error(err)
return
logger.Error(err)
return
}
camStream, err := cam.Stream(context.Background())
// Get the stream from a camera
camStream, err := myCam.Stream(context.Background())
if err!=nil {
logger.Error(err)
return
}

// Get an image from the camera stream
img, release, err := camStream.Next(context.Background())
defer release()

myClassifierService, err := vision.FromRobot(machine, "my_classifier")
if err != nil {
logger.Error(err)
return
logger.Error(err)
return
}
// Get the 2 classifications with the highest confidence scores from the image
classifications, err := myClassifierService.Classifications(context.Background(), img, 2, nil)
if err != nil {
logger.Fatalf("Could not get classifications: %v", err)
logger.Fatalf("Could not get classifications: %v", err)
}
if len(classifications) > 0 {
logger.Info(classifications[0])
logger.Info(classifications[0])
}
```

Expand Down Expand Up @@ -452,16 +448,16 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
```go {class="line-numbers linkable-line-numbers"}
mySegmenterService, err := vision.FromRobot(machine, "my_segmenter")
if err != nil {
logger.Error(err)
return
logger.Error(err)
return
}
// Get the objects from the camera output
objects, err := mySegmenterService.GetObjectPointClouds(context.Background(), "cam", nil)
objects, err := mySegmenterService.GetObjectPointClouds(context.Background(), "my_camera", nil)
if err != nil {
logger.Fatalf("Could not get point clouds: %v", err)
logger.Fatalf("Could not get point clouds: %v", err)
}
if len(objects) > 0 {
logger.Info(objects[0])
logger.Info(objects[0])
}
```

Expand Down Expand Up @@ -558,16 +554,18 @@ if err != nil {

// The data to capture and return from the camera
captOpts := viscapture.CaptureOptions{
ReturnImage: true,
ReturnDetections: true,
ReturnImage: true,
ReturnDetections: true,
}
// Get the captured data for a camera
capture, err := visService.CaptureAllFromCamera(context.Background(), "cam", captOpts, nil)
capture, err := visService.CaptureAllFromCamera(context.Background(), "my_camera", captOpts, nil)
if err != nil {
logger.Fatalf("Could not get capture data from vision service: %v", err)
logger.Fatalf("Could not get capture data from vision service: %v", err)
}
image := capture.Image
detections := capture.Detections
classifications := capture.Classifications
objects := capture.Objects
```

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/services/vision#Service).
Expand Down

0 comments on commit c31ff39

Please sign in to comment.