Skip to content

Commit

Permalink
DOCS-3341: Add missing python methods and fix check (#3858)
Browse files Browse the repository at this point in the history
  • Loading branch information
npentrel authored Jan 17, 2025
1 parent 16e9861 commit 0b1050d
Show file tree
Hide file tree
Showing 20 changed files with 341 additions and 23 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/check_python_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
]

services_page_mapping = {
"motion": "services/motion",
"navigation": "services/navigation",
"slam": "services/slam",
"vision": "services/vision",
"ml": "services/ml"
"motion": "dev/reference/apis/services/motion/",
"navigation": "dev/reference/apis/services/navigation",
"slam": "dev/reference/apis/services/slam",
"vision": "dev/reference/apis/services/vision",
"ml": "dev/reference/apis/services/ml"
}

def is_unimplemented(obj):
Expand Down Expand Up @@ -246,12 +246,12 @@ def parse(type, names):
soup2 = BeautifulSoup(fp, 'html.parser')
else:
if type == "app" or type == "robot":
soup2 = make_soup(f"https://docs.viam.com/program/apis/{service}/")
soup2 = make_soup(f"https://docs.viam.com/dev/reference/apis/{service}/")
else:
if service in services_page_mapping.keys():
soup2 = make_soup(f"https://docs.viam.com/{services_page_mapping[service]}/")
else:
soup2 = make_soup(f"https://docs.viam.com/configure/{type}/{service}/")
soup2 = make_soup(f"https://docs.viam.com/dev/reference/apis/{type}/{service}/")

# Find all links on Docs site soup
all_links = soup2.find_all('a')
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/sdk_protos_map.csv
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,17 @@ gantry,GetGeometries,,,,
## HACK: proto for these (and/or inherited in Go SDK), manually mapping:
gantry,IsMoving,,is_moving,IsMoving,isMoving
gantry,Stop,,stop,Stop,stop
gantry,GetGeometries,,get_geometries,,
gantry,Reconfigure,,,Reconfigure,
gantry,DoCommand,,,,doCommand
gantry,DoCommand,,do_command,,doCommand
gantry,GetResourceName,,get_resource_name,,getResourceName
gantry,Close,,close,Close,

## Generic Component
## NOTED:Generic Component in Go SDK doesn't appear to implement (inherit) these:
generic_component,DoCommand,Yes,do_command,DoCommand,doCommand
# generic_component,GetGeometries,No,,,
generic_component,GetGeometries,No,get_geometries,,
generic_component,DoCommand,,do_command,,doCommand
## HACK: No proto for close, manually mapping:
## NOTED: Go SDK also missing Close, but we have it in our docs?:
generic_component,GetResourceName,No,get_resource_name,,getResourceName
Expand Down Expand Up @@ -128,7 +130,7 @@ input_controller,GetGeometries,,get_geometries,,
input_controller,RegisterControlCallback,,register_control_callback,RegisterControlCallback,
## HACK: proto for these (and/or inherited in Go SDK), manually mapping:
input_controller,Reconfigure,,,Reconfigure,
input_controller,DoCommand,,,,
input_controller,DoCommand,,do_command,,
input_controller,GetResourceName,,get_resource_name,,
input_controller,Close,,close,Close,

Expand Down Expand Up @@ -161,7 +163,7 @@ movement_sensor,GetProperties,Yes,get_properties,Properties,properties
movement_sensor,GetAccuracy,No,get_accuracy,Accuracy,accuracy
movement_sensor,GetLinearAcceleration,Yes,get_linear_acceleration,LinearAcceleration,linearAcceleration
## NOTED: Go SDK doesn't appear to implement this:
# NOT implemented movement_sensor,GetGeometries,No,get_geometries,,
movement_sensor,GetGeometries,No,get_geometries,,
## HACK: No proto for these (and/or inherited in Go SDK), manually mapping:
movement_sensor,GetReadings,Yes,get_readings,Readings,readings
movement_sensor,Reconfigure,No,,Reconfigure,
Expand All @@ -187,6 +189,7 @@ power_sensor,Close,,close,Close,
sensor,GetReadings,Yes,get_readings,Readings,readings
# NOT implemented sensor,GetGeometries,No,get_geometries,,
## HACK: No proto for close (and/or inherited in Go SDK), manually mapping:
sensor,GetGeometries,,get_geometries,,
sensor,Reconfigure,No,,Reconfigure,
# NOT implemented in other languages
sensor,DoCommand,,,,doCommand
Expand Down Expand Up @@ -443,6 +446,7 @@ robot,FrameSystemConfig,,get_frame_system_config,FrameSystemConfig,
robot,TransformPose,,transform_pose,TransformPose,
robot,TransformPCD,,,TransformPointCloud,
robot,StreamStatus,,,,
# DEPRECATED robot,DiscoverComponents,,discover_components,DiscoverComponents,
robot,StopAll,,stop_all,StopAll,
robot,RestartModule,,,RestartModule,
robot,StartSession,,,,
Expand Down
6 changes: 6 additions & 0 deletions static/include/components/apis/generated/arm.md
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,12 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/

- [ResourceName](https://flutter.viam.dev/viam_sdk/ResourceName-class.html)

**Example:**

```dart {class="line-numbers linkable-line-numbers"}
final myArmResourceName = myArm.getResourceName("my_arm");
```

For more information, see the [Flutter SDK Docs](https://flutter.viam.dev/viam_sdk/Arm/getResourceName.html).

{{% /tab %}}
Expand Down
18 changes: 12 additions & 6 deletions static/include/components/apis/generated/board.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ myBoard, err := board.FromRobot(robot, "my_board")
pin, err := myBoard.GPIOPinByName("15")

// Set the pin to high.
err := pin.Set(context.Background(), "true", nil)
err = pin.Set(context.Background(), true, nil)
```

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/components/board#GPIOPin).
Expand Down Expand Up @@ -135,7 +135,7 @@ myBoard, err := board.FromRobot(robot, "my_board")
pin, err := myBoard.GPIOPinByName("15")

// Get if it is true or false that the state of the pin is high.
high := pin.Get(context.Background(), nil)
high, err := pin.Get(context.Background(), nil)
```

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/components/board#GPIOPin).
Expand Down Expand Up @@ -225,7 +225,7 @@ myBoard, err := board.FromRobot(robot, "my_board")
pin, err := myBoard.GPIOPinByName("15")

// Returns the duty cycle.
duty_cycle := pin.PWM(context.Background(), nil)
duty_cycle, err := pin.PWM(context.Background(), nil)
```

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/components/board#GPIOPin).
Expand Down Expand Up @@ -309,7 +309,7 @@ myBoard, err := board.FromRobot(robot, "my_board")
pin, err := myBoard.GPIOPinByName("15")

// Set the duty cycle to .6, meaning that this pin will be in the high state for 60% of the duration of the PWM interval period.
err := pin.SetPWM(context.Background(), .6, nil)
err = pin.SetPWM(context.Background(), .6, nil)
```

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/components/board#GPIOPin).
Expand Down Expand Up @@ -480,7 +480,7 @@ myBoard, err := board.FromRobot(robot, "my_board")
pin, err := myBoard.GPIOPinByName("15")

// Set the PWM frequency of this pin to 1600 Hz.
high := pin.SetPWMFreq(context.Background(), 1600, nil)
err = pin.SetPWMFreq(context.Background(), 1600, nil)
```

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/components/board#GPIOPin).
Expand Down Expand Up @@ -734,7 +734,7 @@ myBoard, err := board.FromRobot(robot, "my_board")
analog, err := myBoard.AnalogByName("my_example_analog")

// Set the pin to value 48.
err := analog.Write(context.Background(), 48, nil)
err = analog.Write(context.Background(), 48, nil)
```

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/components/board#Analog).
Expand Down Expand Up @@ -1292,6 +1292,12 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/

- [ResourceName](https://flutter.viam.dev/viam_sdk/ResourceName-class.html)

**Example:**

```dart {class="line-numbers linkable-line-numbers"}
final myBoardResourceName = myBoard.getResourceName("my_board");
```

For more information, see the [Flutter SDK Docs](https://flutter.viam.dev/viam_sdk/Board/getResourceName.html).

{{% /tab %}}
Expand Down
6 changes: 6 additions & 0 deletions static/include/components/apis/generated/camera.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,12 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/

- [ResourceName](https://flutter.viam.dev/viam_sdk/ResourceName-class.html)

**Example:**

```dart {class="line-numbers linkable-line-numbers"}
final myCameraResourceName = myCamera.getResourceName("my_camera");
```

For more information, see the [Flutter SDK Docs](https://flutter.viam.dev/viam_sdk/Camera/getResourceName.html).

{{% /tab %}}
Expand Down
1 change: 1 addition & 0 deletions static/include/components/apis/generated/gantry-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
| [`Home`](/dev/reference/apis/components/gantry/#home) | Run the homing sequence of the gantry to re-calibrate the axes with respect to the limit switches. |
| [`IsMoving`](/dev/reference/apis/components/gantry/#ismoving) | Get if the gantry is currently moving. |
| [`Stop`](/dev/reference/apis/components/gantry/#stop) | Stop all motion of the gantry. |
| [`GetGeometries`](/dev/reference/apis/components/gantry/#getgeometries) | Get all the geometries associated with the gantry in its current configuration, in the frame of the gantry. |
| [`Reconfigure`](/dev/reference/apis/components/gantry/#reconfigure) | Reconfigure this resource. |
| [`DoCommand`](/dev/reference/apis/components/gantry/#docommand) | Execute model-specific commands that are not otherwise defined by the component API. |
| [`GetResourceName`](/dev/reference/apis/components/gantry/#getresourcename) | Get the `ResourceName` for this gantry with the given name. |
Expand Down
65 changes: 65 additions & 0 deletions static/include/components/apis/generated/gantry.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,39 @@ For more information, see the [Flutter SDK Docs](https://flutter.viam.dev/viam_s
{{% /tab %}}
{{< /tabs >}}

### GetGeometries

Get all the geometries associated with the gantry in its current configuration, in the [frame](/operate/mobility/define-geometry/) of the gantry.
The [motion](/operate/reference/services/motion/) and [navigation](/operate/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.

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

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

- ([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 {class="line-numbers linkable-line-numbers"}
my_gantry = Gantry.from_robot(robot=machine, name="my_gantry")
geometries = await my_gantry.get_geometries()

if geometries:
# Get the center of the first geometry
print(f"Pose of the first geometry's centerpoint: {geometries[0].center}")
```

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

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

### Reconfigure

Reconfigure this resource.
Expand Down Expand Up @@ -490,6 +523,32 @@ For built-in models, model-specific commands are covered with each model's docum
If you are implementing your own gantry 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]): Result of the executed command.

**Raises:**

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

**Example:**

```python {class="line-numbers linkable-line-numbers"}
my_gantry = Gantry.from_robot(robot=machine, name="my_gantry")
command = {"cmd": "test", "data1": 500}
result = await my_gantry.do_command(command)
```

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

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

**Parameters:**
Expand Down Expand Up @@ -547,6 +606,12 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/

- [ResourceName](https://flutter.viam.dev/viam_sdk/ResourceName-class.html)

**Example:**

```dart {class="line-numbers linkable-line-numbers"}
final myGantryResourceName = myGantry.getResourceName("my_gantry");
```

For more information, see the [Flutter SDK Docs](https://flutter.viam.dev/viam_sdk/Gantry/getResourceName.html).

{{% /tab %}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
| Method Name | Description | `viam-micro-server` Support |
| ----------- | ----------- | --------------------------- |
| [`DoCommand`](/dev/reference/apis/components/generic/#docommand) | Execute model-specific commands. | <p class="center-text"><i class="fas fa-check" title="yes"></i></p> |
| [`GetGeometries`](/dev/reference/apis/components/generic/#getgeometries) | Get all the geometries associated with the generic component in its current configuration, in the frame of the generic component. | <p class="center-text"><i class="fas fa-times" title="no"></i></p> |
| [`DoCommand`](/dev/reference/apis/components/generic/#docommand) | Execute model-specific commands. |
| [`GetResourceName`](/dev/reference/apis/components/generic/#getresourcename) | Get the `ResourceName` for this generic component with the given name. | <p class="center-text"><i class="fas fa-times" title="no"></i></p> |
| [`Close`](/dev/reference/apis/components/generic/#close) | Safely shut down the resource and prevent further use. | <p class="center-text"><i class="fas fa-times" title="no"></i></p> |
96 changes: 95 additions & 1 deletion static/include/components/apis/generated/generic_component.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,95 @@ For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/r

**Returns:**

- [Future](https://api.flutter.dev/flutter/dart-async/Future-class.html)\<[Map](https://api.flutter.dev/flutter/dart-core/Map-class.html)\<[String](https://api.flutter.dev/flutter/dart-core/String-class.html), dynamic\>\>
- [Future](https://api.flutter.dev/flutter/dart-core/Future-class.html)\<[Map](https://api.flutter.dev/flutter/dart-core/Map-class.html)\<[String](https://api.flutter.dev/flutter/dart-core/String-class.html), dynamic\>\>

**Example:**

```dart {class="line-numbers linkable-line-numbers"}
// Example using doCommand with an arm component
const command = {'cmd': 'test', 'data1': 500};
var result = myArm.doCommand(command);
```

For more information, see the [Flutter SDK Docs](https://flutter.viam.dev/viam_sdk/Resource/doCommand.html).

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

### GetGeometries

Get all the geometries associated with the generic component in its current configuration, in the [frame](/operate/mobility/define-geometry/) of the generic component.
The [motion](/operate/reference/services/motion/) and [navigation](/operate/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.

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

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

- ([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 {class="line-numbers linkable-line-numbers"}
my_generic_component = Generic.from_robot(robot=machine, name="my_generic_component")
geometries = await my_generic_component.get_geometries()

if geometries:
# Get the center of the first geometry
print(f"Pose of the first geometry's centerpoint: {geometries[0].center}")
```

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

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

### DoCommand

Execute model-specific commands.
If you are implementing your own generic component 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), Any]): Result of the executed command.

**Raises:**

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

**Example:**

```python {class="line-numbers linkable-line-numbers"}
my_generic_component = Generic.from_robot(robot=machine, name="my_generic_component")
command = {"cmd": "test", "data1": 500}
result = await my_generic_component.do_command(command)
```

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

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

**Parameters:**

- `command` [Map](https://api.flutter.dev/flutter/dart-core/Map-class.html)\<[String](https://api.flutter.dev/flutter/dart-core/String-class.html), dynamic\> (required)

**Returns:**

- [Future](https://api.flutter.dev/flutter/dart-core/Future-class.html)\<[Map](https://api.flutter.dev/flutter/dart-core/Map-class.html)\<[String](https://api.flutter.dev/flutter/dart-core/String-class.html), dynamic\>\>

**Example:**

Expand Down Expand Up @@ -112,6 +200,12 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/

- [ResourceName](https://flutter.viam.dev/viam_sdk/ResourceName-class.html)

**Example:**

```dart {class="line-numbers linkable-line-numbers"}
final myGenericResourceName = myGeneric.getResourceName("my_generic");
```

For more information, see the [Flutter SDK Docs](https://flutter.viam.dev/viam_sdk/Generic/getResourceName.html).

{{% /tab %}}
Expand Down
Loading

0 comments on commit 0b1050d

Please sign in to comment.