rosros 0.2.5
Simple unified interface to ROS1 / ROS2 Python API
Loading...
Searching...
No Matches
core.py
Go to the documentation of this file.
1"""
2Stand-ins for `rospy.core` in ROS2.
3
4------------------------------------------------------------------------------
5This file is part of rosros - simple unified interface to ROS1 / ROS2.
6Released under the BSD License.
7
8@author Erki Suurjaak
9@created 30.05.2022
10@modified 23.06.2022
11------------------------------------------------------------------------------
12"""
13## @namespace rosros.rospify.core
14
15from .. import ros2
16from . import exceptions
17from . log import logdebug, logwarn, loginfo, logout, logerr, logfatal, \
18 logdebug_throttle, logwarn_throttle, loginfo_throttle, logerr_throttle, \
19 logfatal_throttle, \
20 logdebug_throttle_identical, logwarn_throttle_identical, \
21 loginfo_throttle_identical, logerr_throttle_identical, \
22 logfatal_throttle_identical, \
23 logdebug_once, logwarn_once, loginfo_once, logerr_once, logfatal_once
24
25
27 """Returns whether ROS2 has been started and shut down."""
28 return ros2.SHUTDOWN
29
30
31def signal_shutdown(reason):
32 """
33 Initiates shutdown process.
34
35 @param reason ignored (ROS1 compatibility stand-in)
36 """
37 ros2.shutdown()
38
39
41 """Returns empty string (ROS1 compatibility stand-in)."""
42 return ""
43
44
45def get_ros_root(required=False, env=None):
46 """
47 Returns rclpy share directory.
48
49 In ROS1, this returns a path along the lines of "/opt/ros/noetic/share/ros".
50
51 @param env ignored (ROS1 compatibility stand-in)
52 @param required fail with ROSException if not found
53 @return rclpy share directory path
54
55 @throws ROSException if `require` is True and result unavailable
56 """
57 try:
58 return ros2.get_package_share_directory("rclpy")
59 except KeyError:
60 if required:
61 raise exceptions.ROSException("ROS root share directory not set.")
62 return None
63
65ROSRPC = "rosrpc://"
66
67def parse_rosrpc_uri(uri):
68 """
69 Utility function for parsing ROS-RPC URIs.
70
71 @param uri ROSRPC URI
72 @return (address, port)
74 @throws ParameterInvalid if uri is not a valid ROSRPC URI
75 """
76 if uri.startswith(ROSRPC):
77 dest_addr = uri[len(ROSRPC):]
78 else:
79 raise exceptions.ParameterInvalid("Invalid protocol for ROS service URL: %s" % uri)
80 try:
81 if "/" in dest_addr:
82 dest_addr = dest_addr[:dest_addr.find("/")]
83 dest_addr, dest_port = dest_addr.split(":")
84 dest_port = int(dest_port)
85 except Exception as e:
86 raise exceptions.ParameterInvalid("ROS service URL is invalid: %s" % uri) from e
87 return dest_addr, dest_port
88
89
90__all__ = [
91 "ROSRPC", "get_node_uri", "get_ros_root", "is_shutdown", "parse_rosrpc_uri", "signal_shutdown",
92 "logdebug", "logwarn", "loginfo", "logout", "logerr", "logfatal",
93 "logdebug_throttle", "logwarn_throttle", "loginfo_throttle", "logerr_throttle",
94 "logfatal_throttle",
95 "logdebug_throttle_identical", "logwarn_throttle_identical", "loginfo_throttle_identical",
96 "logerr_throttle_identical", "logfatal_throttle_identical",
97 "logdebug_once", "logwarn_once", "loginfo_once", "logerr_once", "logfatal_once"
98]
Base exception class for ROS clients.
Definition exceptions.py:54
is_shutdown()
Returns whether ROS2 has been started and shut down.
Definition core.py:26
get_node_uri()
Returns empty string (ROS1 compatibility stand-in).
Definition core.py:40