Skip to content

Commit 7abda81

Browse files
author
Emerson Knapp
committed
Print 'Infinite' for infinite durations in topic endpoint info
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
1 parent 75d9948 commit 7abda81

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

rclpy/rclpy/duration.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ def nanoseconds(self):
3434
def __repr__(self):
3535
return 'Duration(nanoseconds={0})'.format(self.nanoseconds)
3636

37+
def __str__(self):
38+
if self == Duration.Infinite():
39+
return 'Infinite'
40+
return f'{self.nanoseconds} nanoseconds'
41+
3742
def __eq__(self, other):
3843
if isinstance(other, Duration):
3944
return self.nanoseconds == other.nanoseconds
@@ -77,5 +82,9 @@ def from_msg(cls, msg):
7782
raise TypeError('Must pass a builtin_interfaces.msg.Duration object')
7883
return cls(seconds=msg.sec, nanoseconds=msg.nanosec)
7984

85+
@classmethod
86+
def Infinite(cls):
87+
return cls(nanoseconds=_rclpy.rclpy_RMW_DURATION_INFINITE)
88+
8089
def get_c_duration(self):
8190
return self._duration_handle

rclpy/rclpy/topic_endpoint_info.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ def __str__(self):
166166
result += 'QoS profile:\n'
167167
result += ' Reliability: %s\n' % self.qos_profile.reliability.name
168168
result += ' Durability: %s\n' % self.qos_profile.durability.name
169-
result += ' Lifespan: %d nanoseconds\n' % self.qos_profile.lifespan.nanoseconds
170-
result += ' Deadline: %d nanoseconds\n' % self.qos_profile.deadline.nanoseconds
169+
result += ' Lifespan: %s\n' % str(self.qos_profile.lifespan)
170+
result += ' Deadline: %s\n' % str(self.qos_profile.deadline)
171171
result += ' Liveliness: %s\n' % self.qos_profile.liveliness.name
172-
result += ' Liveliness lease duration: %d nanoseconds' % \
173-
self.qos_profile.liveliness_lease_duration.nanoseconds
172+
result += ' Liveliness lease duration: %s' % \
173+
str(self.qos_profile.liveliness_lease_duration)
174174
return result

rclpy/src/rclpy/_rclpy_pybind11.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ PYBIND11_MODULE(_rclpy_pybind11, m) {
6969
.value("RCL_PUBLISHER_LIVELINESS_LOST", RCL_PUBLISHER_LIVELINESS_LOST)
7070
.value("RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS", RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS);
7171

72+
m.attr("rclpy_RMW_DURATION_INFINITE") = py::int_(rmw_time_total_nsec(RMW_DURATION_INFINITE));
73+
7274
py::register_exception<rclpy::RCUtilsError>(m, "RCUtilsError", PyExc_RuntimeError);
7375
py::register_exception<rclpy::RMWError>(m, "RMWError", PyExc_RuntimeError);
7476
auto rclerror = py::register_exception<rclpy::RCLError>(m, "RCLError", PyExc_RuntimeError);

rclpy/test/test_time.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,7 @@ def test_seconds_nanoseconds(self):
228228
assert (1, int(5e8)) == Time(seconds=1, nanoseconds=5e8).seconds_nanoseconds()
229229
assert (1, int(5e8)) == Time(seconds=0, nanoseconds=15e8).seconds_nanoseconds()
230230
assert (0, 0) == Time().seconds_nanoseconds()
231+
232+
def test_infinite_duration(self):
233+
duration = Duration.Infinite()
234+
assert str(duration) == 'Infinite'

0 commit comments

Comments
 (0)