Skip to content
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

Print 'Infinite' for infinite durations in topic endpoint info #722

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions rclpy/rclpy/duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def nanoseconds(self):
def __repr__(self):
return 'Duration(nanoseconds={0})'.format(self.nanoseconds)

def __str__(self):
if self == Infinite:
return 'Infinite'
return f'{self.nanoseconds} nanoseconds'

def __eq__(self, other):
if isinstance(other, Duration):
return self.nanoseconds == other.nanoseconds
Expand Down Expand Up @@ -79,3 +84,7 @@ def from_msg(cls, msg):

def get_c_duration(self):
return self._duration_handle


# Constant representing an infinite amount of time.
Infinite = Duration(nanoseconds=_rclpy.RMW_DURATION_INFINITE)
29 changes: 15 additions & 14 deletions rclpy/rclpy/topic_endpoint_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,18 @@ def __eq__(self, other):
for slot in self.__slots__)

def __str__(self):
result = 'Node name: %s\n' % self.node_name
result += 'Node namespace: %s\n' % self.node_namespace
result += 'Topic type: %s\n' % self.topic_type
result += 'Endpoint type: %s\n' % self.endpoint_type.name
result += 'GID: %s\n' % '.'.join(format(x, '02x') for x in self.endpoint_gid)
result += 'QoS profile:\n'
result += ' Reliability: %s\n' % self.qos_profile.reliability.name
result += ' Durability: %s\n' % self.qos_profile.durability.name
result += ' Lifespan: %d nanoseconds\n' % self.qos_profile.lifespan.nanoseconds
result += ' Deadline: %d nanoseconds\n' % self.qos_profile.deadline.nanoseconds
result += ' Liveliness: %s\n' % self.qos_profile.liveliness.name
result += ' Liveliness lease duration: %d nanoseconds' % \
self.qos_profile.liveliness_lease_duration.nanoseconds
return result
gid = '.'.join(format(x, '02x') for x in self.endpoint_gid)
return '\n'.join([
f'Node name: {self.node_name}',
f'Node namespace: {self.node_namespace}',
f'Topic type: {self.topic_type}',
f'Endpoint type: {self.endpoint_type.name}',
f'GID: {gid}',
'QoS profile:',
f' Reliability: {self.qos_profile.reliability.name}',
f' Durability: {self.qos_profile.durability.name}',
f' Lifespan: {self.qos_profile.lifespan}',
f' Deadline: {self.qos_profile.deadline}',
f' Liveliness: {self.qos_profile.liveliness.name}',
f' Liveliness lease duration: {self.qos_profile.liveliness_lease_duration}',
])
1 change: 1 addition & 0 deletions rclpy/src/rclpy/_rclpy_pybind11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ PYBIND11_MODULE(_rclpy_pybind11, m) {
.value("STEADY_TIME", RCL_STEADY_TIME);

m.attr("RCL_DEFAULT_DOMAIN_ID") = py::int_(RCL_DEFAULT_DOMAIN_ID);
m.attr("RMW_DURATION_INFINITE") = py::int_(rmw_time_total_nsec(RMW_DURATION_INFINITE));

py::enum_<rcl_clock_change_t>(m, "ClockChange")
.value(
Expand Down
5 changes: 5 additions & 0 deletions rclpy/test/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from rclpy.clock import ClockType
from rclpy.duration import Duration
from rclpy.duration import Infinite
from rclpy.time import Time

from test_msgs.msg import Builtins
Expand Down Expand Up @@ -228,3 +229,7 @@ def test_seconds_nanoseconds(self):
assert (1, int(5e8)) == Time(seconds=1, nanoseconds=5e8).seconds_nanoseconds()
assert (1, int(5e8)) == Time(seconds=0, nanoseconds=15e8).seconds_nanoseconds()
assert (0, 0) == Time().seconds_nanoseconds()

def test_infinite_duration(self):
duration = Infinite
assert str(duration) == 'Infinite'