Enable ros2topic delay command#139
Conversation
aa2656c to
623d3ef
Compare
|
Thank you for working on this feature. In the current form the patch is pretty difficult to review. Please split the patch into separate commit with roughly the following structure:
|
|
Thanks for guide, I'll resubmit commits early this week. |
623d3ef to
3b02cf8
Compare
|
patch splitted, be ready for review. |
| 'topic', | ||
| help='Topic name to be calcurated the delay') | ||
| arg.completer = TopicNameCompleter( | ||
| include_hidden_topics_key='include_hidden_topics') |
There was a problem hiding this comment.
There is currently no include_hidden_topics argument here? I guess you need to add it in order to work.
There was a problem hiding this comment.
Could work, same usage ref to pub.py and list.py
from ros2topic.api import TopicNameCompleter
ros2cli/ros2topic/ros2topic/api/__init__.py
Lines 45 to 46 in ce9077f
There was a problem hiding this comment.
Never mind, the argument is added one level above in
ros2cli/ros2topic/ros2topic/command/topic.py
Lines 25 to 27 in ce9077f
topic.
ros2topic/ros2topic/verb/delay.py
Outdated
| arg.completer = TopicNameCompleter( | ||
| include_hidden_topics_key='include_hidden_topics') | ||
| parser.add_argument( | ||
| '--window', '-w', default=-1, |
There was a problem hiding this comment.
Please define the type of the argument as int than argparse will already ensure the type for you. It would make sense if the default value would be a valid value so that users don't have to specify one.
ros2topic/ros2topic/verb/delay.py
Outdated
|
|
||
| # can't have infinite window size due to memory restrictions | ||
| if window_size < 0: | ||
| if window_size < 0 or window_size > 50000: |
There was a problem hiding this comment.
The input of window size should be checked after argparse and if negative rejected (rather than silently changed).
Please don't hard code arbitrary limits like 50000. It should be the users choice to use a larger window if they know what they are doing.
ros2topic/ros2topic/verb/delay.py
Outdated
| return | ||
|
|
||
| curr = curr_rostime.to_sec() | ||
| curr = curr_rostime.nanoseconds * 1e-9 |
There was a problem hiding this comment.
You could avoid the conversion to floating point seconds and keep using the Time class for the operations. That would avoid any rounding errors.
There was a problem hiding this comment.
fixed 2c01515
As ROS there is to_sec and to_time method, but I not found similar in ROS2, especially about msg_header.stamp. this is builtin_interface/Time type, does there is function like stamp.to_time()?
ros2topic/ros2topic/verb/delay.py
Outdated
| return t_type, t, msgevalgen(topic[len(t):]) | ||
| else: | ||
| return None, None, None | ||
| timer = node.create_timer(1, timer_callback) |
There was a problem hiding this comment.
You could register rt.print_delay here directly getting rid of the local function.
| self.msg_tn = curr | ||
|
|
||
| if len(self.delays) > self.window_size - 1: | ||
| if len(self.delays) > self.window_size: |
There was a problem hiding this comment.
Please describe why this was changed.
There was a problem hiding this comment.
To fix the issue that no data print when set window as 1,
ros2 topic delay /image -w 1
There was a problem hiding this comment.
Don't know why here need to window_size - 1 ?
|
|
||
| self.last_msg_tn = self.msg_tn | ||
| return mean, min_delta, max_delta, std_dev, n + 1 | ||
| return mean, min_delta, max_delta, std_dev, n |
There was a problem hiding this comment.
Please describe why this was changed.
|
thanks for review, I have added changes for fixing. |
ros2topic/ros2topic/verb/delay.py
Outdated
|
|
||
| # can't have infinite window size due to memory restrictions | ||
| if window_size < 0: | ||
| window_size = 50000 |
There was a problem hiding this comment.
This "magic" upper bound is nowhere visible to the user. Please use it as a default value of the argument instead (and ensure in code that the user didn't pass a negative value).
There was a problem hiding this comment.
this is original design, I have not changed while porting. If user did not set the value. As previous design, the default value of window is -1, and here will re-set to max 50000 as memory restrictions.
There was a problem hiding this comment.
Sure, it would still benefit from being improved.
ros2topic/ros2topic/verb/delay.py
Outdated
| % (delay, min_delta, max_delta, std_dev, window)) | ||
|
|
||
|
|
||
| def _rostopic_delay(node, topic, window_size=-1, blocking=False): |
There was a problem hiding this comment.
I would suggest making window_size a required argument - otherwise this function needs to pick an opaque default value.
How does blocking=False work if the msg_class can't be determined yet?
There was a problem hiding this comment.
This is original design. I think general user will not concern about window_size and just easy to use the tool. It will give user a little more trouble every time to type --window as required argument. It may also confuse user about the window meaning (first time I use rostopic, I really don't know what this window mean :))
Sorry but not considered when blocking=False, thanks for review, fixed by 0e79d06 (replaced by c3e506f )
There was a problem hiding this comment.
set blocking=True by default. commit again: c3e506f
There was a problem hiding this comment.
(commit: 2cd09fe): Is this fixing acceptable to set DEFULT_WINDOW_SIZE? (ref to cho.py code). User can input any value (unsigned int) or use default. The DEFULT_WINDOW_SIZE is set as 10000 and could be any other value.
ros2topic/ros2topic/verb/delay.py
Outdated
| curr_nanosec = curr_rostime.to_msg().nanosec | ||
|
|
||
| delay = ((curr_sec + curr_nanosec * 1e-9) - | ||
| (msg.header.stamp.sec + msg.header.stamp.nanosec * 1e-9)) |
There was a problem hiding this comment.
You should be able to compute the delay (as a Duration) by doing curr_rostime.to_msg() - rclpy.Time.from_msg(msg.header.stamp) (see https://github.com/ros2/rclpy/blob/62012d3650de790d89c725232451c4e998b396fb/rclpy/rclpy/time.py#L131) and store the duration instance in self.delays.
ros2topic/ros2topic/verb/delay.py
Outdated
| self.msg_tn = curr | ||
| self.delays = [] | ||
| else: | ||
| # store the duration instrance in self.delays |
There was a problem hiding this comment.
Spelling: "instrance" -> "instance".
ros2topic/ros2topic/verb/delay.py
Outdated
| else: | ||
| # store the duration instrance in self.delays | ||
| duration = (curr_rostime - Time.from_msg(msg.header.stamp)) | ||
| self.delays.append(duration.nanoseconds * 1e-9) |
There was a problem hiding this comment.
This isn't doing what the comment two lines above states - it still stores the duration as a floating point number in seconds.
ros2topic/ros2topic/verb/delay.py
Outdated
|
|
||
| # can't have infinite window size due to memory restrictions | ||
| if window_size < 0: | ||
| window_size = 50000 |
There was a problem hiding this comment.
Sure, it would still benefit from being improved.
e9d5095 to
34e400a
Compare
d057f2c to
2cd09fe
Compare
|
@dirk-thomas commits with minor changes are submitted. Do you have any other suggests? so that I could sync with you and fix immediately when you are online:) |
|
Thank you for the updates! I just ran CI builds for this branch and the results look good: Can you please add the BSD license to the package manifest (as in https://github.com/ros2/ros2cli/pull/133/files#diff-27285248de861ae535a0217d2fa40c9cR11). To keep the git history a bit shorter can you then reduce the commits as follows:
After that this should be ready to be merged. |
This file is originally copied from: https://github.com/ros/ros_comm/blob/6e5016f4b2266d8a60c9a1e163c4928b8fc7115e/tools/rostopic/src/rostopic/__init__.py Signed-off-by: Chris Ye <chris.ye@intel.com>
0e2f7ff to
a317f3c
Compare
Signed-off-by: Chris Ye <chris.ye@intel.com>
* remove irrelevant code and reserve hz code (ros has only one __init__.py file include all topic commands, ros2 has splitted commands to isolated file) * major functional changes of delay cmd with ROS2 API * update license format to pass test_copyright * use Time duration to compute the delay * check window_size as non-negative integer, fix no print when set window as 1 Signed-off-by: Chris Ye <chris.ye@intel.com>
|
CI looks good, and the patch set has been redone according to what @dirk-thomas suggested. I also took a brief look at it, and it looks OK to me. I'm going to merge this; thanks for the contribution. |
|
@dirk-thomas @clalancette thanks for review and merge. |
Porting rostopic delay command from ROS to ROS2. Display delay of topic from timestamp in header.
Usage: ros2 topic delay /topic_name
Signed-off-by: Chris Ye chris.ye@intel.com
Connects to: #132