-
Notifications
You must be signed in to change notification settings - Fork 60
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
RSDK-4788: Add Readings to Python SDK #459
Conversation
Warning your change may break code samples. If your change modifies any of the following functions please contact @viamrobotics/fleet-management. Thanks!
|
@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) |
…s/viam-python-sdk into rsdk-4788
d53203b
to
c32a8e5
Compare
de8bca8
to
f0a5654
Compare
@@ -5,6 +5,7 @@ | |||
|
|||
from ..service_base import ServiceBase | |||
from . import GeoObstacle, GeoPoint, Mode, Waypoint | |||
from viam.proto.service.navigation import Path |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"))], |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@njooma @benjirewis @clintpurser all good? |
There was a problem hiding this 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
There was a problem hiding this 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:
- 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
- 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
- Can you also add
get_readings
in theExampleMovementSensor
@@ -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]: |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
@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. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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"), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"), |
There was a problem hiding this comment.
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)
fix imports (from sensor to common) and use
GetReadingsRequest/Response
for movement sensor and power sensor