:py:mod:`viam.services.navigation` ================================== .. py:module:: viam.services.navigation Submodules ---------- .. toctree:: :titlesonly: :maxdepth: 1 client/index.rst navigation/index.rst service/index.rst Package Contents ---------------- Classes ~~~~~~~ .. autoapisummary:: viam.services.navigation.GeoObstacle viam.services.navigation.GeoPoint viam.services.navigation.MapType viam.services.navigation.Mode viam.services.navigation.Path viam.services.navigation.Waypoint viam.services.navigation.Navigation .. py:class:: GeoObstacle(*, location: global___GeoPoint | None = ..., geometries: collections.abc.Iterable[global___Geometry] | None = ...) Bases: :py:obj:`google.protobuf.message.Message` GeoObstacle contains information about the geometric structure of an obstacle and the location of the obstacle, captured in latitude and longitude. .. py:property:: location :type: global___GeoPoint Location of the obstacle .. py:property:: geometries :type: google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___Geometry] Geometries that describe the obstacle, where embedded Pose data is with respect to the specified location .. py:method:: HasField(field_name: Literal[location, b'location']) -> bool Checks if a certain field is set for the message. For a oneof group, checks if any field inside is set. Note that if the field_name is not defined in the message descriptor, :exc:`ValueError` will be raised. :param field_name: The name of the field to check for presence. :type field_name: str :returns: Whether a value has been set for the named field. :rtype: bool :raises ValueError: if the `field_name` is not a member of this message. .. py:class:: GeoPoint(*, latitude: float = ..., longitude: float = ...) Bases: :py:obj:`google.protobuf.message.Message` Abstract base class for protocol messages. Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below. .. py:attribute:: latitude :type: float .. py:attribute:: longitude :type: float .. py:class:: MapType Bases: :py:obj:`_MapType` MapType represents the various types of maps the navigation service can ingest. .. py:class:: Mode Bases: :py:obj:`_Mode` .. py:class:: Path(*, destination_waypoint_id: str = ..., geopoints: collections.abc.Iterable[viam.gen.common.v1.common_pb2.GeoPoint] | None = ...) Bases: :py:obj:`google.protobuf.message.Message` A user provided destination and the set of geopoints that the robot is expected to take to get there .. py:property:: geopoints :type: google.protobuf.internal.containers.RepeatedCompositeFieldContainer[viam.gen.common.v1.common_pb2.GeoPoint] List of geopoints that the motion planner output to reach the destination The first geopoint is the starting position of the robot for that path .. py:attribute:: destination_waypoint_id :type: str The id of the user specified waypoint .. py:class:: Waypoint(*, id: str = ..., location: viam.gen.common.v1.common_pb2.GeoPoint | None = ...) Bases: :py:obj:`google.protobuf.message.Message` Abstract base class for protocol messages. Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below. .. py:property:: location :type: viam.gen.common.v1.common_pb2.GeoPoint .. py:attribute:: id :type: str .. py:method:: HasField(field_name: Literal[location, b'location']) -> bool Checks if a certain field is set for the message. For a oneof group, checks if any field inside is set. Note that if the field_name is not defined in the message descriptor, :exc:`ValueError` will be raised. :param field_name: The name of the field to check for presence. :type field_name: str :returns: Whether a value has been set for the named field. :rtype: bool :raises ValueError: if the `field_name` is not a member of this message. .. py:class:: Navigation(name: str) Bases: :py:obj:`viam.services.service_base.ServiceBase` Navigation represents a Navigation service. This acts as an abstract base class for any drivers representing specific navigation service implementations. This cannot be used on its own. If the ``__init__()`` function is overridden, it must call the ``super().__init__()`` function. .. py:attribute:: SUBTYPE :type: Final .. py:method:: get_paths(*, timeout: Optional[float]) -> List[viam.services.navigation.Path] :abstractmethod: :async: Get each path, the series of geo points the robot plans to travel through to get to a destination waypoint, in the machine’s motion planning. :: my_nav = NavigationClient.from_robot(robot=robot, name="my_nav_service") # Get a list containing each path stored by the navigation service paths = await my_nav.get_paths() :param timeout: An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call. :type timeout: Optional[float] :returns: An array comprised of Paths, where each path is either a user-provided destination or a Waypoint, along with the corresponding set of geopoints. This outlines the route the machine is expected to take to reach the specified destination or Waypoint. :rtype: List[navigation.Path] .. py:method:: get_location(*, timeout: Optional[float]) -> viam.services.navigation.GeoPoint :abstractmethod: :async: Get the current location of the robot in the navigation service. :: my_nav = NavigationClient.from_robot(robot=robot, name="my_nav_service") # Get the current location of the robot in the navigation service location = await my_nav.get_location() :param timeout: An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call. :type timeout: Optional[float] :returns: The current location of the robot in the navigation service, represented in a GeoPoint with latitude and longitude values. :rtype: navigation.GeoPoint .. py:method:: get_obstacles(*, timeout: Optional[float]) -> List[viam.services.navigation.GeoObstacle] :abstractmethod: :async: Get an array or list of the obstacles currently in the service’s data storage. These are objects designated for the robot to avoid when navigating. These include all transient obstacles which are discovered by the vision services configured for the navigation service, in addition to the obstacles that are configured as a part of the service. :: my_nav = NavigationClient.from_robot(robot=robot, name="my_nav_service") # Get a list containing each obstacle stored by the navigation service obstacles = await my_nav.get_obstacles() :param timeout: An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call. :type timeout: Optional[float] :returns: A list comprised of each GeoObstacle in the service’s data storage. These are objects designated for the robot to avoid when navigating. :rtype: List[navigation.GeoObstacle] .. py:method:: get_waypoints(*, timeout: Optional[float]) -> List[viam.services.navigation.Waypoint] :abstractmethod: :async: Get an array of waypoints currently in the service’s data storage. These are locations designated within a path for the robot to navigate to. :: my_nav = NavigationClient.from_robot(robot=robot, name="my_nav_service") # Get a list containing each waypoint stored by the navigation service waypoints = await my_nav.get_waypoints() :param timeout: An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call. :type timeout: Optional[float] :returns: An array comprised of each Waypoint in the service’s data storage. These are locations designated within a path for the robot to navigate to. :rtype: List[navigation.Waypoint] .. py:method:: add_waypoint(point: viam.services.navigation.GeoPoint, *, timeout: Optional[float]) :abstractmethod: :async: Add a waypoint to the service’s data storage. :: my_nav = NavigationClient.from_robot(robot=robot, name="my_nav_service") # Create a new waypoint with latitude and longitude values of 0 degrees location = GeoPoint(latitude=0, longitude=0) # Add your waypoint to the service's data storage await my_nav.add_waypoint(point=location) :param point: The current location of the robot in the navigation service, represented in a GeoPoint with latitude and longitude values. :type point: navigation.GeoPoint :param timeout: An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call. :type timeout: Optional[float] .. py:method:: remove_waypoint(id: str, *, timeout: Optional[float]) :abstractmethod: :async: Remove a waypoint from the service’s data storage. If the robot is currently navigating to this waypoint, the motion will be canceled, and the robot will proceed to the next waypoint. :: my_nav = NavigationClient.from_robot(robot=robot, name="my_nav_service") # Remove the waypoint matching that ObjectID from the service's data storage await my_nav.remove_waypoint(waypoint_id) :param id: The MongoDB ObjectID of the Waypoint to remove from the service’s data storage. :type id: str :param timeout: An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call. :type timeout: Optional[float] .. py:method:: get_mode(*, timeout: Optional[float]) -> viam.services.navigation.Mode.ValueType :abstractmethod: :async: Get the Mode the service is operating in. There are two options for modes: MODE_MANUAL or MODE_WAYPOINT. MODE_WAYPOINT: Start to look for added waypoints and begin autonomous navigation. MODE_MANUAL: Stop autonomous navigation between waypoints and allow the base to be controlled manually. :: my_nav = NavigationClient.from_robot(robot=robot, name="my_nav_service") # Get the Mode the service is operating in await my_nav.get_mode() :param timeout: An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call. :type timeout: Optional[float] :returns: The Mode the service is operating in. :rtype: navigation.Mode.ValueType .. py:method:: set_mode(mode: viam.services.navigation.Mode.ValueType, *, timeout: Optional[float]) :abstractmethod: :async: Set the Mode the service is operating in. There are two options for modes: MODE_MANUAL or MODE_WAYPOINT. MODE_WAYPOINT: Start to look for added waypoints and begin autonomous navigation. MODE_MANUAL: Stop autonomous navigation between waypoints and allow the base to be controlled manually. :: my_nav = NavigationClient.from_robot(robot=robot, name="my_nav_service") # Set the Mode the service is operating in to MODE_WAYPOINT and begin navigation await my_nav.set_mode(Mode.ValueType.MODE_WAYPOINT) :param timeout: An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call. :type timeout: Optional[float] :param mode: The Mode for the service to operate in. :type mode: navigation.Mode.ValueType .. py:method:: get_properties(*, timeout: Optional[float]) -> viam.services.navigation.MapType.ValueType :abstractmethod: :async: Get information about the navigation service. :: my_nav = NavigationClient.from_robot(robot=robot, name="my_nav_service") # Get the properties of the current navigation service. nav_properties = await my_nav.get_properties() :param timeout: An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call. :type timeout: Optional[float] :returns: Information about the type of map the service is using. :rtype: MapType.ValueType .. py:method:: from_robot(robot: viam.robot.client.RobotClient, name: str) -> typing_extensions.Self :classmethod: Get the service named ``name`` from the provided robot. :: async def connect() -> ViamClient: # Replace "" (including brackets) with your API key and "" with your API key ID dial_options = DialOptions.with_api_key("", "") return await ViamClient.create_from_dial_options(dial_options) async def main(): robot = await connect() # Can be used with any resource, using the motion service as an example motion = MotionClient.from_robot(robot=robot, name="builtin") robot.close() :param robot: The robot :type robot: RobotClient :param name: The name of the service :type name: str :returns: The service, if it exists on the robot :rtype: Self .. py:method:: do_command(command: Mapping[str, viam.utils.ValueTypes], *, timeout: Optional[float] = None, **kwargs) -> Mapping[str, viam.utils.ValueTypes] :abstractmethod: :async: Send/receive arbitrary commands. :: motion = MotionClient.from_robot(robot, "builtin") my_command = { "cmnd": "dosomething", "someparameter": 52 } # Can be used with any resource, using the motion service as an example await motion.do_command(command=my_command) :param command: The command to execute :type command: Dict[str, ValueTypes] :returns: Result of the executed command :rtype: Dict[str, ValueTypes] .. py:method:: get_resource_name(name: str) -> viam.proto.common.ResourceName :classmethod: Get the ResourceName for this Resource with the given name :: # Can be used with any resource, using an arm as an example my_arm_name = my_arm.get_resource_name("my_arm") :param name: The name of the Resource :type name: str :returns: The ResourceName of this Resource :rtype: ResourceName .. py:method:: get_operation(kwargs: Mapping[str, Any]) -> viam.operations.Operation Get the ``Operation`` associated with the currently running function. When writing custom resources, you should get the ``Operation`` by calling this function and check to see if it's cancelled. If the ``Operation`` is cancelled, then you can perform any necessary (terminating long running tasks, cleaning up connections, etc. ). :param kwargs: The kwargs object containing the operation :type kwargs: Mapping[str, Any] :returns: The operation associated with this function :rtype: viam.operations.Operation .. py:method:: close() :async: Safely shut down the resource and prevent further use. Close must be idempotent. Later configuration may allow a resource to be "open" again. If a resource does not want or need a close function, it is assumed that the resource does not need to return errors when future non-Close methods are called. :: await component.close()