Skip to content

DOCS-2902: Edit machine management api from QA #748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
37 changes: 29 additions & 8 deletions src/viam/robot/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ async def get_status(self, components: Optional[List[ResourceName]] = None) -> L

# Get the status of the resources on the machine.
statuses = await machine.get_status()
resource_statuses = machine_status.resources

Args:
components (Optional[List[viam.proto.common.ResourceName]]): Optional list of
Expand Down Expand Up @@ -713,7 +714,24 @@ async def transform_pose(

::

pose = await machine.transform_pose(PoseInFrame(), "origin")
from viam.proto.common import Pose, PoseInFrame

pose = Pose(
x=1.0, # X coordinate in mm
y=2.0, # Y coordinate in mm
z=3.0, # Z coordinate in mm
o_x=0.0, # X component of orientation vector
o_y=0.0, # Y component of orientation vector
o_z=0.0, # Z component of orientation vector
theta=0.0 # Orientation angle in degrees
)

pose_in_frame = PoseInFrame(
reference_frame="world",
pose=pose
)

transformed_pose = await machine.transform_pose(pose_in_frame, "world")

Args:

Expand Down Expand Up @@ -741,12 +759,15 @@ async def discover_components(
queries: List[DiscoveryQuery],
) -> List[Discovery]:
"""
Get the list of discovered component configurations.
Get a list of discovered potential component configurations, for example listing different supported resolutions. Currently only works for some cameras.
Returns module names for modules.

::

from viam.proto.robot import DiscoveryQuery

# Define a new discovery query.
q = machine.DiscoveryQuery(subtype=acme.API, model="some model")
q = DiscoveryQuery(subtype="camera", model="webcam")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For subtype, you could do Camera.SUBTYPE.resource_subtype which is a bit more verbose but fully typechecked.

This way also works, but just in case people don't know how to get the subtype? Up to y'all, just showing an additional way of doing it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way seems more straightforward but thank you


# Define a list of discovery queries.
qs = [q]
Expand All @@ -756,10 +777,10 @@ async def discover_components(

Args:

queries (List[viam.proto.robot.DiscoveryQuery]): The list of component models to lookup configurations for.
queries (List[viam.proto.robot.DiscoveryQuery]): The list of component models to lookup potential configurations for.

Returns:
List[Discovery]: A list of discovered component configurations.
List[Discovery]: A list of discovered potential component configurations.

For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
"""
Expand Down Expand Up @@ -829,7 +850,7 @@ async def get_cloud_metadata(self) -> GetCloudMetadataResponse:

::

metadata = machine.get_cloud_metadata()
metadata = await machine.get_cloud_metadata()
print(metadata.machine_id)
print(metadata.machine_part_id)
print(metadata.primary_org_id)
Expand All @@ -854,7 +875,7 @@ async def shutdown(self):

::

machine.shutdown()
await machine.shutdown()

Raises:
GRPCError: Raised with DeadlineExceeded status if shutdown request times out, or if
Expand Down Expand Up @@ -890,7 +911,7 @@ async def get_version(self) -> GetVersionResponse:

::

result = machine.get_version()
result = await machine.get_version()
print(result.platform)
print(result.version)
print(result.api_version)
Expand Down