Skip to content

Commit f91f7a3

Browse files
authored
RSDK-11273: Modify Python motion wrappers to send strings (#1003)
1 parent a426b1f commit f91f7a3

File tree

3 files changed

+63
-68
lines changed

3 files changed

+63
-68
lines changed

src/viam/services/motion/client.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
GeoPoint,
1111
Pose,
1212
PoseInFrame,
13-
ResourceName,
1413
Transform,
1514
WorldState,
1615
)
@@ -54,7 +53,7 @@ def __init__(self, name: str, channel: Channel):
5453

5554
async def move(
5655
self,
57-
component_name: ResourceName,
56+
component_name: str,
5857
destination: PoseInFrame,
5958
world_state: Optional[WorldState] = None,
6059
constraints: Optional[Constraints] = None,
@@ -77,9 +76,9 @@ async def move(
7776

7877
async def move_on_globe(
7978
self,
80-
component_name: ResourceName,
79+
component_name: str,
8180
destination: GeoPoint,
82-
movement_sensor_name: ResourceName,
81+
movement_sensor_name: str,
8382
obstacles: Optional[Sequence[GeoGeometry]] = None,
8483
heading: Optional[float] = None,
8584
configuration: Optional[MotionConfiguration] = None,
@@ -106,9 +105,9 @@ async def move_on_globe(
106105

107106
async def move_on_map(
108107
self,
109-
component_name: ResourceName,
108+
component_name: str,
110109
destination: Pose,
111-
slam_service_name: ResourceName,
110+
slam_service_name: str,
112111
configuration: Optional[MotionConfiguration] = None,
113112
obstacles: Optional[Sequence[Geometry]] = None,
114113
*,
@@ -131,7 +130,7 @@ async def move_on_map(
131130

132131
async def stop_plan(
133132
self,
134-
component_name: ResourceName,
133+
component_name: str,
135134
*,
136135
extra: Optional[Mapping[str, ValueTypes]] = None,
137136
timeout: Optional[float] = None,
@@ -149,7 +148,7 @@ async def stop_plan(
149148

150149
async def get_plan(
151150
self,
152-
component_name: ResourceName,
151+
component_name: str,
153152
last_plan_only: bool = False,
154153
execution_id: Optional[str] = None,
155154
*,
@@ -189,7 +188,7 @@ async def list_plan_statuses(
189188

190189
async def get_pose(
191190
self,
192-
component_name: ResourceName,
191+
component_name: str,
193192
destination_frame: str,
194193
supplemental_transforms: Optional[Sequence[Transform]] = None,
195194
*,

src/viam/services/motion/motion.py

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
else:
88
from typing_extensions import TypeAlias
99

10-
from viam.proto.common import GeoGeometry, Geometry, GeoPoint, Pose, PoseInFrame, ResourceName, Transform, WorldState
10+
from viam.proto.common import GeoGeometry, Geometry, GeoPoint, Pose, PoseInFrame, Transform, WorldState
1111
from viam.proto.service.motion import Constraints, GetPlanResponse, MotionConfiguration, PlanStatusWithID
1212
from viam.resource.types import API, RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_SERVICE
1313
from viam.utils import ValueTypes
@@ -33,7 +33,7 @@ class Motion(ServiceBase):
3333
@abc.abstractmethod
3434
async def move(
3535
self,
36-
component_name: ResourceName,
36+
component_name: str,
3737
destination: PoseInFrame,
3838
world_state: Optional[WorldState] = None,
3939
constraints: Optional[Constraints] = None,
@@ -44,18 +44,17 @@ async def move(
4444
"""Plan and execute a movement to move the component specified to its goal destination.
4545
4646
Note: Frames designated with respect to components can also be used as the ``component_name`` when calling for a move. This
47-
technique allows for planning and moving the frame itself to the ``destination``. To do so, simply create a resource name with
48-
originating ReferenceFrame's name. Then pass in the resource name into ``component_name``. Ex::
47+
technique allows for planning and moving the frame itself to the ``destination``.
48+
To do so, simply pass in a string into ``component_name``. Ex::
4949
50-
resource_name = Gripper.get_resource_name("externalFrame")
51-
success = await MotionServiceClient.move(resource_name, ...)
50+
success = await MotionServiceClient.move("externalFrame", ...)
5251
5352
::
5453
5554
motion = MotionClient.from_robot(robot=machine, name="builtin")
5655
57-
# Assumes a gripper configured with name "my_gripper" on the machine
58-
gripper_name = Gripper.get_resource_name("my_gripper")
56+
# Assumes "my_gripper" on the machine
57+
gripper_name = "my_gripper"
5958
my_frame = "my_gripper_offset"
6059
6160
goal_pose = Pose(x=0, y=0, z=300, o_x=0, o_y=0, o_z=1, theta=0)
@@ -69,7 +68,7 @@ async def move(
6968
extra={})
7069
7170
Args:
72-
component_name (viam.proto.common.ResourceName): Name of a component on a given robot.
71+
component_name (str): Name of a component on a given robot.
7372
destination (viam.proto.common.PoseInFrame): The destination to move to, expressed as a ``Pose`` and the frame in which it was
7473
observed.
7574
world_state (viam.proto.common.WorldState): When supplied, the motion service will create a plan that obeys any constraints
@@ -95,9 +94,9 @@ async def move(
9594
@abc.abstractmethod
9695
async def move_on_globe(
9796
self,
98-
component_name: ResourceName,
97+
component_name: str,
9998
destination: GeoPoint,
100-
movement_sensor_name: ResourceName,
99+
movement_sensor_name: str,
101100
obstacles: Optional[Sequence[GeoGeometry]] = None,
102101
heading: Optional[float] = None,
103102
configuration: Optional[MotionConfiguration] = None,
@@ -120,24 +119,23 @@ async def move_on_globe(
120119
121120
motion = MotionClient.from_robot(robot=machine, name="builtin")
122121
123-
# Get the ResourceNames of the base and movement sensor
124-
my_base_resource_name = Base.get_resource_name("my_base")
125-
mvmnt_sensor_resource_name = MovementSensor.get_resource_name(
126-
"my_movement_sensor")
122+
# Get the names of the base and movement sensor
123+
my_base_name = "my_base"
124+
mvmnt_sensor_name = "my_movement_sensor"
127125
# Define a destination GeoPoint at the GPS coordinates [0, 0]
128126
my_destination = movement_sensor.GeoPoint(latitude=0, longitude=0)
129127
130128
# Move the base component to the designated geographic location, as reported by the movement sensor
131129
execution_id = await motion.move_on_globe(
132-
component_name=my_base_resource_name,
130+
component_name=my_base_name,
133131
destination=my_destination,
134-
movement_sensor_name=mvmnt_sensor_resource_name)
132+
movement_sensor_name=mvmnt_sensor_name)
135133
136134
Args:
137-
component_name (ResourceName): The ResourceName of the base to move.
135+
component_name (str): The name of the base to move.
138136
destination (GeoPoint): The location of the component's destination, represented in geographic notation as a
139137
GeoPoint (lat, lng).
140-
movement_sensor_name (ResourceName): The ResourceName of the movement sensor that you want to use to check
138+
movement_sensor_name (str): The name of the movement sensor that you want to use to check
141139
the machine's location.
142140
obstacles (Optional[Sequence[GeoGeometry]]): Obstacles to consider when planning the motion of the component,
143141
with each represented as a GeoGeometry. Default: None
@@ -170,9 +168,9 @@ async def move_on_globe(
170168
@abc.abstractmethod
171169
async def move_on_map(
172170
self,
173-
component_name: ResourceName,
171+
component_name: str,
174172
destination: Pose,
175-
slam_service_name: ResourceName,
173+
slam_service_name: str,
176174
configuration: Optional[MotionConfiguration] = None,
177175
obstacles: Optional[Sequence[Geometry]] = None,
178176
*,
@@ -194,23 +192,23 @@ async def move_on_map(
194192
195193
motion = MotionClient.from_robot(robot=machine, name="builtin")
196194
197-
# Get the ResourceNames of the base component and SLAM service
198-
my_base_resource_name = Base.get_resource_name("my_base")
199-
my_slam_service_name = SLAMClient.get_resource_name("my_slam_service")
195+
# Get the names of the base component and SLAM service
196+
my_base_name = "my_base"
197+
my_slam_service_name = "my_slam_service"
200198
201199
# Define a destination pose with respect to the origin of the map from the SLAM service "my_slam_service"
202200
my_pose = Pose(y=10)
203201
204202
# Move the base component to the destination pose of Y=10, a location of
205203
# (0, 10, 0) in respect to the origin of the map
206-
execution_id = await motion.move_on_map(component_name=my_base_resource_name,
204+
execution_id = await motion.move_on_map(component_name=my_base_name,
207205
destination=my_pose,
208206
slam_service_name=my_slam_service_name)
209207
210208
Args:
211-
component_name (ResourceName): The ResourceName of the base to move.
209+
component_name (str): The name of the base to move.
212210
destination (Pose): The destination, which can be any Pose with respect to the SLAM map's origin.
213-
slam_service_name (ResourceName): The ResourceName of the SLAM service from which the SLAM map is requested.
211+
slam_service_name (str): The name of the SLAM service from which the SLAM map is requested.
214212
configuration (Optional[MotionConfiguration]): The configuration you want to set across this machine for this motion service.
215213
This parameter and each of its fields are optional.
216214
@@ -237,7 +235,7 @@ async def move_on_map(
237235
@abc.abstractmethod
238236
async def stop_plan(
239237
self,
240-
component_name: ResourceName,
238+
component_name: str,
241239
*,
242240
extra: Optional[Mapping[str, ValueTypes]] = None,
243241
timeout: Optional[float] = None,
@@ -251,11 +249,11 @@ async def stop_plan(
251249
# Assuming a `move_on_globe()` started the execution
252250
# Stop the base component which was instructed to move by `move_on_globe()`
253251
# or `move_on_map()`
254-
my_base_resource_name = Base.get_resource_name("my_base")
252+
my_base_name = "my_base"
255253
await motion.stop_plan(component_name=mvmnt_sensor)
256254
257255
Args:
258-
component_name (ResourceName): The component to stop
256+
component_name (str): The component to stop
259257
260258
For more information, see `Motion service <https://docs.viam.com/dev/reference/apis/services/motion/#stopplan>`_.
261259
"""
@@ -264,7 +262,7 @@ async def stop_plan(
264262
@abc.abstractmethod
265263
async def get_plan(
266264
self,
267-
component_name: ResourceName,
265+
component_name: str,
268266
last_plan_only: bool = False,
269267
execution_id: Optional[str] = None,
270268
*,
@@ -291,12 +289,12 @@ async def get_plan(
291289
::
292290
293291
motion = MotionClient.from_robot(robot=machine, name="builtin")
294-
my_base_resource_name = Base.get_resource_name("my_base")
292+
my_base_name = "my_base"
295293
# Get the plan(s) of the base component which was instructed to move by `MoveOnGlobe()` or `MoveOnMap()`
296-
resp = await motion.get_plan(component_name=my_base_resource_name)
294+
resp = await motion.get_plan(component_name=my_base_name)
297295
298296
Args:
299-
component_name (ResourceName): The component to stop
297+
component_name (str): The component to stop
300298
last_plan_only (Optional[bool]): If supplied, the response will only return the last plan for the component / execution.
301299
execution_id (Optional[str]): If supplied, the response will only return plans with the provided execution_id.
302300
@@ -343,7 +341,7 @@ async def list_plan_statuses(
343341
@abc.abstractmethod
344342
async def get_pose(
345343
self,
346-
component_name: ResourceName,
344+
component_name: str,
347345
destination_frame: str,
348346
supplemental_transforms: Optional[Sequence[Transform]] = None,
349347
*,
@@ -359,7 +357,7 @@ async def get_pose(
359357
# (``Arm``, ``Base``, etc).
360358
361359
# Create a `component_name`:
362-
component_name = Gripper.get_resource_name("my_gripper")
360+
component_name = "my_gripper"
363361
364362
from viam.components.gripper import Gripper
365363
from viam.services.motion import MotionClient
@@ -368,12 +366,12 @@ async def get_pose(
368366
robot = await connect()
369367
370368
motion = MotionClient.from_robot(robot=machine, name="builtin")
371-
gripperName = Gripper.get_resource_name("my_gripper")
369+
gripperName = "my_gripper"
372370
gripperPoseInWorld = await motion.get_pose(component_name=gripperName,
373371
destination_frame="world")
374372
375373
Args:
376-
component_name (viam.proto.common.ResourceName): Name of a component on a robot.
374+
component_name (str): Name of a component on a robot.
377375
destination_frame (str): Name of the desired reference frame.
378376
supplemental_transforms (Optional[List[viam.proto.common.Transform]]): Transforms used to augment the robot's frame while
379377
calculating pose.

0 commit comments

Comments
 (0)