1414 Transform ,
1515 WorldState ,
1616)
17+
1718from viam .proto .service .motion import (
1819 Constraints ,
1920 GetPlanRequest ,
3334 StopPlanRequest ,
3435 StopPlanResponse ,
3536)
37+
3638from viam .resource .rpc_client_base import ReconfigurableResourceRPCClientBase
3739from viam .resource .types import RESOURCE_NAMESPACE_RDK , RESOURCE_TYPE_SERVICE , Subtype
3840from viam .services .service_client_base import ServiceClientBase
@@ -74,6 +76,24 @@ async def move(
7476 resource_name = Arm.get_resource_name("externalFrame")
7577 success = await MotionServiceClient.move(resource_name, ...)
7678
79+ ::
80+
81+ motion = MotionClient.from_robot(robot=robot, name="builtin")
82+
83+ # Assumes a gripper configured with name "my_gripper" on the machine
84+ gripper_name = Gripper.get_resource_name("my_gripper")
85+ my_frame = "my_gripper_offset"
86+
87+ goal_pose = Pose(x=0, y=0, z=300, o_x=0, o_y=0, o_z=1, theta=0)
88+
89+ # Move the gripper
90+ moved = await motion.move(component_name=gripper_name,
91+ destination=PoseInFrame(reference_frame="myFrame",
92+ pose=goal_pose),
93+ world_state=worldState,
94+ constraints={},
95+ extra={})
96+
7797 Args:
7898 component_name (viam.proto.common.ResourceName): Name of a component on a given robot.
7999 destination (viam.proto.common.PoseInFrame): The destination to move to, expressed as a ``Pose`` and the frame in which it was
@@ -121,6 +141,23 @@ async def move_on_globe(
121141
122142 You can monitor the progress of the ``move_on_globe()`` call by querying ``get_plan()`` and ``list_plan_statuses()``.
123143
144+ ::
145+
146+ motion = MotionClient.from_robot(robot=robot, name="builtin")
147+
148+ # Get the ResourceNames of the base and movement sensor
149+ my_base_resource_name = Base.get_resource_name("my_base")
150+ mvmnt_sensor_resource_name = MovementSensor.get_resource_name(
151+ "my_movement_sensor")
152+ # Define a destination GeoPoint at the GPS coordinates [0, 0]
153+ my_destination = movement_sensor.GeoPoint(latitude=0, longitude=0)
154+
155+ # Move the base component to the designated geographic location, as reported by the movement sensor
156+ execution_id = await motion.move_on_globe(
157+ component_name=my_base_resource_name,
158+ destination=my_destination,
159+ movement_sensor_name=mvmnt_sensor_resource_name)
160+
124161 Args:
125162 component_name (ResourceName): The ResourceName of the base to move.
126163 destination (GeoPoint): The location of the component’s destination, represented in geographic notation as a
@@ -188,6 +225,23 @@ async def move_on_map(
188225
189226 You can monitor the progress of the ``move_on_map()`` call by querying ``get_plan()`` and ``list_plan_statuses()``.
190227
228+ ::
229+
230+ motion = MotionClient.from_robot(robot=robot, name="builtin")
231+
232+ # Get the ResourceNames of the base component and SLAM service
233+ my_base_resource_name = Base.get_resource_name("my_base")
234+ my_slam_service_name = SLAMClient.get_resource_name("my_slam_service")
235+
236+ # Define a destination pose with respect to the origin of the map from the SLAM service "my_slam_service"
237+ my_pose = Pose(y=10)
238+
239+ # Move the base component to the destination pose of Y=10, a location of
240+ # (0, 10, 0) in respect to the origin of the map
241+ execution_id = await motion.move_on_map(component_name=my_base_resource_name,
242+ destination=my_pose,
243+ slam_service_name=my_slam_service_name)
244+
191245 Args:
192246 component_name (ResourceName): The ResourceName of the base to move.
193247 destination (Pose): The destination, which can be any Pose with respect to the SLAM map’s origin.
@@ -232,6 +286,14 @@ async def stop_plan(
232286 ):
233287 """Stop a component being moved by an in progress ``move_on_globe()`` or ``move_on_map()`` call.
234288
289+ ::
290+
291+ # Assuming a `move_on_globe()` started the execution
292+ # Stop the base component which was instructed to move by `move_on_globe()`
293+ # or `move_on_map()`
294+ my_base_resource_name = Base.get_resource_name("my_base")
295+ await motion.stop_plan(component_name=mvmnt_sensor)
296+
235297 Args:
236298 component_name (ResourceName): The component to stop
237299
@@ -258,7 +320,7 @@ async def get_plan(
258320 extra : Optional [Mapping [str , ValueTypes ]] = None ,
259321 timeout : Optional [float ] = None ,
260322 ) -> GetPlanResponse :
261- """By default: returns the plan history of the most recent ``move_on_globe()`` or ``move_on_map()``call to move a component.
323+ """By default: returns the plan history of the most recent ``move_on_globe()`` or ``move_on_map()`` call to move a component.
262324
263325 The plan history for executions before the most recent can be requested by providing an ExecutionID in the request.
264326
@@ -275,6 +337,13 @@ async def get_plan(
275337
276338 All repeated fields are in time ascending order.
277339
340+ ::
341+
342+ motion = MotionClient.from_robot(robot=robot, name="builtin")
343+ my_base_resource_name = Base.get_resource_name("my_base")
344+ # Get the plan(s) of the base component which was instructed to move by `MoveOnGlobe()` or `MoveOnMap()`
345+ resp = await motion.get_plan(component_name=my_base_resource_name)
346+
278347 Args:
279348 component_name (ResourceName): The component to stop
280349 last_plan_only (Optional[bool]): If supplied, the response will only return the last plan for the component / execution
@@ -311,6 +380,12 @@ async def list_plan_statuses(
311380
312381 All repeated fields are in chronological order.
313382
383+ ::
384+
385+ motion = MotionClient.from_robot(robot=robot, name="builtin")
386+ # List the plan statuses of the motion service within the TTL
387+ resp = await motion.list_plan_statuses()
388+
314389 Args:
315390 only_active_plans (Optional[bool]): If supplied, the response will filter out any plans that are not executing
316391
@@ -346,6 +421,18 @@ async def get_pose(
346421 Note that the example uses the ``Arm`` class, but any component class that inherits from ``ComponentBase`` will work
347422 (``Base``, ``Gripper``, etc).
348423
424+ ::
425+
426+ from viam.components.gripper import Gripper
427+ from viam.services.motion import MotionClient
428+
429+ # Assume that the connect function is written and will return a valid machine.
430+ robot = await connect()
431+
432+ motion = MotionClient.from_robot(robot=robot, name="builtin")
433+ gripperName = Gripper.get_resource_name("my_gripper")
434+ gripperPoseInWorld = await motion.get_pose(component_name=gripperName,
435+ destination_frame="world")
349436
350437 Args:
351438 component_name (viam.proto.common.ResourceName): Name of a component on a robot.
@@ -371,6 +458,18 @@ async def get_pose(
371458 async def do_command (self , command : Mapping [str , ValueTypes ], * , timeout : Optional [float ] = None , ** __ ) -> Mapping [str , ValueTypes ]:
372459 """Send/receive arbitrary commands
373460
461+ ::
462+
463+ # Access the motion service
464+ motion = MotionClient.from_robot(robot=robot, name="builtin")
465+
466+ my_command = {
467+ "command": "dosomething",
468+ "someparameter": 52
469+ }
470+
471+ await motion.do_command(my_command)
472+
374473 Args:
375474 command (Dict[str, ValueTypes]): The command to execute
376475
0 commit comments