Skip to content

RSDK-4788: Add Readings to Python SDK #459

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
merged 11 commits into from
Oct 24, 2023

Conversation

martha-johnston
Copy link
Contributor

fix imports (from sensor to common) and use GetReadingsRequest/Response for movement sensor and power sensor

@martha-johnston martha-johnston requested a review from a team as a code owner October 10, 2023 19:16
@github-actions
Copy link
Contributor

Warning your change may break code samples. If your change modifies any of the following functions please contact @viamrobotics/fleet-management. Thanks!

component function
base is_moving
board gpio_pin_by_name
camera get_image
encoder get_position
motor is_moving
sensor get_readings
servo get_position
arm get_end_position
gantry get_lengths
gripper is_moving
movement_sensor get_linear_acceleration
input_controller get_controls
audio get_properties
pose_tracker get_poses
power_sensor get_power
motion get_pose
vision get_classifications_from_camera

@benjirewis benjirewis requested a review from njooma October 11, 2023 14:02
@martha-johnston
Copy link
Contributor Author

@njooma @benjirewis @clintpurser does anyone know if I should be running make buf locally and uploading that? or should those be generated through GitHub actions? seems like test aren't passing because it doesn't have the new api methods (but it should because api was merged)

@@ -5,6 +5,7 @@

from ..service_base import ServiceBase
from . import GeoObstacle, GeoPoint, Mode, Waypoint
from viam.proto.service.navigation import Path
Copy link
Member

Choose a reason for hiding this comment

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

@njooma here and elsewhere we were just importing Path from viam.proto.service.navigation. I see some other API types being imported from .; how does that work? We added Path (along with GetPathsRequest and GetPathsResponse) to src/viam/proto/service/navigation/__init__.py, but I don't think we were able to find Path in . here.

Copy link
Member

Choose a reason for hiding this comment

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

The . syntax is only if the class is included in the src/viam/services/navigation/__init__.py, not the .../proto/... file.

@@ -17,7 +17,8 @@
"gantry": PoseInFrame(reference_frame="gantry", pose=Pose(x=2, y=3, z=4, o_x=3, o_y=4, o_z=5, theta=21)),
}
MOTION_CONFIGURATION = MotionConfiguration(
vision_services=[ResourceName(namespace="rdk", type="service", subtype="vision", name="viz1")],
obstacle_detectors=[ObstacleDetector(vision_service=ResourceName(namespace="rdk", type="service", subtype="vision", name="viz1"),
camera=ResourceName(namespace="rdk", type="component", subtype="camera", name="cam1"))],
Copy link
Member

Choose a reason for hiding this comment

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

I assume it's fine to just use a random camera here in the test?

Copy link
Member

Choose a reason for hiding this comment

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

Anything that can return GetObjectPointCluds for an obstacle. which cameras do.

@@ -36,6 +39,11 @@ def __init__(self, name: str, channel: Channel):
self.client = NavigationServiceStub(channel)
super().__init__(name)

async def get_paths(self, *, timeout: Optional[float] = None) -> List[Path]:
Copy link
Member

Choose a reason for hiding this comment

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

[q] Why do we return API types to users? I thought we would convert the API type to some native Python class and return that to the user?

Copy link
Member

Choose a reason for hiding this comment

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

I want to request that follow-up API cleanup that doesn't have to do with Martha's readings change be handled in a follow-up ticket. This design does look wrong, though ) I think it should return a Python class but I don't want to make a decision given we're doing this on the fly.

Copy link
Member

Choose a reason for hiding this comment

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

It's not bad to return a protobuf message. It's actually preferred IMO. This way we don't have to create a bunch of classes that mirror the proto, nor we do we have to keep those classes updated.

Copy link
Member

@benjirewis benjirewis Oct 23, 2023

Choose a reason for hiding this comment

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

@njooma that makes sense. Per recent conversation in the SDKs channel, it seems like it's just language-dependent whether the protos are "good enough" to not need native-mirrored types.

@randhid
Copy link
Member

randhid commented Oct 20, 2023

@njooma @benjirewis @clintpurser all good?

@randhid randhid requested a review from benjirewis October 23, 2023 13:10
Copy link
Member

@benjirewis benjirewis left a comment

Choose a reason for hiding this comment

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

LGTM but probably wait for final approval from @njooma

Copy link
Member

@njooma njooma left a comment

Choose a reason for hiding this comment

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

@martha-johnston couple of Qs:

  1. In the Flutter SDK, you changed MovementSensor so that it's no longer a subclass of Sensor. Do we want to do that here too? https://github.com/viamrobotics/viam-python-sdk/pull/459/files#diff-dae80644bfff17971abcac39a1b73496a043c30b4c86c0b72de2cc8d7869f9e2R14
  2. The return type in the docstring should maybe be updated to reflect that anything could be returned, since it's no longer defined by the SDK
  3. Can you also add get_readings in the ExampleMovementSensor

@@ -36,6 +39,11 @@ def __init__(self, name: str, channel: Channel):
self.client = NavigationServiceStub(channel)
super().__init__(name)

async def get_paths(self, *, timeout: Optional[float] = None) -> List[Path]:
Copy link
Member

Choose a reason for hiding this comment

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

It's not bad to return a protobuf message. It's actually preferred IMO. This way we don't have to create a bunch of classes that mirror the proto, nor we do we have to keep those classes updated.

@@ -5,6 +5,7 @@

from ..service_base import ServiceBase
from . import GeoObstacle, GeoPoint, Mode, Waypoint
from viam.proto.service.navigation import Path
Copy link
Member

Choose a reason for hiding this comment

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

The . syntax is only if the class is included in the src/viam/services/navigation/__init__.py, not the .../proto/... file.

@martha-johnston
Copy link
Contributor Author

@njooma I think I covered everything... I do want movement sensor to no longer be a subclass of sensor so that should be fixed now, I updated the docstring, and added get_readings to ExampleMovementSensor. also updated the nav init.py file so path could be imported along with GeoPoint, Waypoint, etc.

Copy link
Member

@njooma njooma left a comment

Choose a reason for hiding this comment

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

Almost!! One minor change. Approving it because you should be able to merge it in once you add that additional change

@@ -1,5 +1,5 @@
from viam.proto.common import GeoObstacle, GeoPoint
from viam.proto.service.navigation import Mode, Waypoint
from viam.proto.service.navigation import Mode, Waypoint, Path
Copy link
Member

Choose a reason for hiding this comment

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

This will work, but you should also add it in the __all__ list below

@@ -60,7 +60,6 @@
ResourceName(namespace=RESOURCE_NAMESPACE_RDK, type=RESOURCE_TYPE_COMPONENT, subtype="camera", name="camera1"),
ResourceName(namespace=RESOURCE_NAMESPACE_RDK, type=RESOURCE_TYPE_COMPONENT, subtype="motor", name="motor1"),
ResourceName(namespace=RESOURCE_NAMESPACE_RDK, type=RESOURCE_TYPE_COMPONENT, subtype="movement_sensor", name="movement_sensor1"),
ResourceName(namespace=RESOURCE_NAMESPACE_RDK, type=RESOURCE_TYPE_COMPONENT, subtype="sensor", name="movement_sensor1"),
Copy link
Contributor Author

@martha-johnston martha-johnston Oct 24, 2023

Choose a reason for hiding this comment

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

made the __all__ change, but this was causing the tests to fail... I removed this line because they were both called "movement_sensor1" but this was of subtype "sensor", and now the tests pass. Just want to make sure this checks out @njooma

Copy link
Member

Choose a reason for hiding this comment

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

Ohh nice find. There's another spot where this should be updated, but I made a ticket for it for myself for later (not required for this)

@@ -60,7 +60,6 @@
ResourceName(namespace=RESOURCE_NAMESPACE_RDK, type=RESOURCE_TYPE_COMPONENT, subtype="camera", name="camera1"),
ResourceName(namespace=RESOURCE_NAMESPACE_RDK, type=RESOURCE_TYPE_COMPONENT, subtype="motor", name="motor1"),
ResourceName(namespace=RESOURCE_NAMESPACE_RDK, type=RESOURCE_TYPE_COMPONENT, subtype="movement_sensor", name="movement_sensor1"),
ResourceName(namespace=RESOURCE_NAMESPACE_RDK, type=RESOURCE_TYPE_COMPONENT, subtype="sensor", name="movement_sensor1"),
Copy link
Member

Choose a reason for hiding this comment

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

Ohh nice find. There's another spot where this should be updated, but I made a ticket for it for myself for later (not required for this)

@martha-johnston martha-johnston merged commit b69b05d into viamrobotics:main Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants