Skip to content

Commit

Permalink
Print 'Infinite' for infinite durations in topic endpoint info
Browse files Browse the repository at this point in the history
Signed-off-by: Emerson Knapp <[email protected]>
  • Loading branch information
Emerson Knapp committed Mar 22, 2021
1 parent 75d9948 commit 7abda81
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
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 == Duration.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 @@ -77,5 +82,9 @@ def from_msg(cls, msg):
raise TypeError('Must pass a builtin_interfaces.msg.Duration object')
return cls(seconds=msg.sec, nanoseconds=msg.nanosec)

@classmethod
def Infinite(cls):
return cls(nanoseconds=_rclpy.rclpy_RMW_DURATION_INFINITE)

def get_c_duration(self):
return self._duration_handle
8 changes: 4 additions & 4 deletions rclpy/rclpy/topic_endpoint_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ def __str__(self):
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 += ' Lifespan: %s\n' % str(self.qos_profile.lifespan)
result += ' Deadline: %s\n' % str(self.qos_profile.deadline)
result += ' Liveliness: %s\n' % self.qos_profile.liveliness.name
result += ' Liveliness lease duration: %d nanoseconds' % \
self.qos_profile.liveliness_lease_duration.nanoseconds
result += ' Liveliness lease duration: %s' % \
str(self.qos_profile.liveliness_lease_duration)
return result
2 changes: 2 additions & 0 deletions rclpy/src/rclpy/_rclpy_pybind11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ PYBIND11_MODULE(_rclpy_pybind11, m) {
.value("RCL_PUBLISHER_LIVELINESS_LOST", RCL_PUBLISHER_LIVELINESS_LOST)
.value("RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS", RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS);

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

py::register_exception<rclpy::RCUtilsError>(m, "RCUtilsError", PyExc_RuntimeError);
py::register_exception<rclpy::RMWError>(m, "RMWError", PyExc_RuntimeError);
auto rclerror = py::register_exception<rclpy::RCLError>(m, "RCLError", PyExc_RuntimeError);
Expand Down
4 changes: 4 additions & 0 deletions rclpy/test/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,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 = Duration.Infinite()
assert str(duration) == 'Infinite'

0 comments on commit 7abda81

Please sign in to comment.