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

[rostopic] Show stat when rostopic echo --noarr/nostr #724

Closed
wants to merge 7 commits into from

Conversation

wkentaro
Copy link
Contributor

Should this be another option like --statarr?
Because this kind of function is not needed for string for me but for only array field.

screen shot 2015-12-31 at 3 17 50 am

@wkentaro wkentaro force-pushed the rostopic-echo-show-stat branch from b30b6e0 to 5037d5b Compare December 30, 2015 18:22
if value_transform:
# this operation is necessary because value_transform does change the type of message
# and that causes not strified values next time
val = value_untransform_fn(val)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be easier to read like this:

value_untransform_fn = None
if value_transform:
    val, value_untransform_fn = value_transform(val)
text = genpy.message.strify_message(val, indent=indent, time_offset=time_offset, current_time=current_time, field_filter=field_filter, fixed_numeric_width=fixed_numeric_width)
if value_untransform_fn is not None:
    # this operation is necessary because value_transform does change the type of message
    # and that causes not strified values next time
    val = value_untransform_fn(val)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I updated the commit.

@wjwwood
Copy link
Member

wjwwood commented Dec 30, 2015

Looks reasonable to me.

@wkentaro wkentaro force-pushed the rostopic-echo-show-stat branch from 5037d5b to a59ac5a Compare December 31, 2015 04:17
@wkentaro
Copy link
Contributor Author

wkentaro commented Jan 3, 2016

Thanks for the feedback, I updated the commit.

@@ -608,7 +608,8 @@ class CallbackEcho(object):
def __init__(self, topic, msg_eval, plot=False, filter_fn=None,
echo_clear=False, echo_all_topics=False,
offset_time=False, count=None,
field_filter_fn=None, fixed_numeric_width=None):
field_filter_fn=None, value_transform_fn=None,
fixed_numeric_width=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not change the order of existing arguments but add new arguments at the end.

Same below.

@wkentaro
Copy link
Contributor Author

wkentaro commented Mar 2, 2016

I have updated strified -> stringified.

@dirk-thomas
Copy link
Member

Some of the unit tests are currently failing. Please see the referenced Jenkins builds.

"""
:param plot: if ``True``, echo in plotting-friendly format, ``bool``
:param filter_fn: function that evaluates to ``True`` if message is to be echo'd, ``fn(topic, msg)``
:param echo_all_topics: (optional) if ``True``, echo all messages in bag, ``bool``
:param offset_time: (optional) if ``True``, display time as offset from current time, ``bool``
:param count: number of messages to echo, ``None`` for infinite, ``int``
:param field_filter_fn: filter the fields that are strified for Messages, ``fn(Message)->iter(str)``
:param field_filter_fn: filter the fields that are stringified for Messages, ``fn(Message)->iter(str)``
:param value_transform_fn: transform the values of Messages, ``fn(Message)->Message``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of line 622.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, I have fixed.

return val, untransform_fn
return value_transform

def create_field_filter(echo_nostr, echo_noarr):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this function is used anywhere outside by now it doesn't filter anything anymore.

@wkentaro
Copy link
Contributor Author

wkentaro commented May 7, 2016

Removed the field_filter function.

@dirk-thomas
Copy link
Member

Since you have removed all unit tests for create_field_filter are you planning to readd them for the new function?

@wkentaro
Copy link
Contributor Author

I'm not planning to readd them, because filtering field it not supported after this PR.
Aside from actually removing(filtering) the fields (string/array) this PR shows the stats for them.

@wkentaro wkentaro changed the title rostopic echo: Show stat when --noarr/nostr [rostopic] Show stat when rostopic echo --noarr/nostr May 11, 2016
@wkentaro
Copy link
Contributor Author

wkentaro commented May 18, 2016

Is this solution OK? I removed the create_field_filter function which will be no longer used.

@dirk-thomas
Copy link
Member

create_field_filter is a public function of this Python package. While it might not be used within this file anymore other packages might still be using it and would break if it gets removed. So I don't think it should be removed since such a breakage is not necessary.

@wkentaro wkentaro force-pushed the rostopic-echo-show-stat branch from b57a5bb to 1da29f8 Compare May 19, 2016 05:32
@wkentaro
Copy link
Contributor Author

@dirk-thomas
OK, I restored the create_field_filter function.

And also, I found a bug of this code with nested messages as below.
It is fixed now with the last commit.
BEFORE

% rostopic echo /raw_image_bgr/image_color --nostr --noarr
header: 
  seq: 48
  stamp: 
    secs: 1463637710
    nsecs: 575849056
  frame_id: camera
height: 1080
width: 1920
encoding: <string length: 4>
is_bigendian: 0
step: 5760
data: <array type: uint8, length: 6220800>

AFTER

% rostopic echo /raw_image_bgr/image_color --nostr --noarr
header: 
  seq: 46
  stamp: 
    secs: 1463637665
    nsecs: 575885057
  frame_id: <string length: 6>
height: 1080
width: 1920
encoding: <string length: 4>
is_bigendian: 0
step: 5760
data: <array type: uint8, length: 6220800>

@wkentaro
Copy link
Contributor Author

wkentaro commented May 19, 2016

@ros-pull-request-builder rostest this please

@wkentaro wkentaro closed this May 19, 2016
@wkentaro wkentaro reopened this May 19, 2016
@wkentaro
Copy link
Contributor Author

Test passed. Please review again when you have time.

@dirk-thomas
Copy link
Member

The patch looks good. But I was thinking if the effort for transforming and then untransforming the message is necessary. Wouldn't it be easier to just copy the message and update the copied message? For efficiency you could also implement a custom copy operation which already avoids to copy the string / array fields in the first place?

@wkentaro
Copy link
Contributor Author

wkentaro commented Jun 3, 2016

The patch looks good. But I was thinking if the effort for transforming and then untransforming the message is necessary. Wouldn't it be easier to just copy the message and update the copied message? For efficiency you could also implement a custom copy operation which already avoids to copy the string / array fields in the first place?

Thanks for the suggestion. I worked around for a while, and the problem when the transformed message was untransformed will be fixed by correct _field_type of the message class. So I created TransformedMessage as the dummy class for printing.

@wkentaro wkentaro force-pushed the rostopic-echo-show-stat branch from 1a62372 to 19fb710 Compare June 3, 2016 18:13
@wkentaro
Copy link
Contributor Author

ping

1 similar comment
@wkentaro
Copy link
Contributor Author

wkentaro commented Aug 5, 2016

ping

@dirk-thomas
Copy link
Member

I am sorry for the late response but I currently have to focus on a different project and don't have much time to review ROS tickets.

The patch looks good now. Thank you for iterating on it. I cherry-picked the changed to the kinetic-devel branch with two small cosmetic changes: e0f6397

--- a/tools/rostopic/src/rostopic/__init__.py
+++ b/tools/rostopic/src/rostopic/__init__.py
@@ -831,8 +831,7 @@ class CallbackEcho(object):
             val = [ord(x) for x in val]
         if value_transform is not None:
             val = value_transform(val)
-        text = genpy.message.strify_message(val, indent=indent, time_offset=time_offset, current_time=current_time, field_filter=field_filter, fixed_numeric_width=fixed_numeric_width)
-        return text
+        return genpy.message.strify_message(val, indent=indent, time_offset=time_offset, current_time=current_time, field_filter=field_filter, fixed_numeric_width=fixed_numeric_width)

     def callback(self, data, callback_args, current_time=None):
         """
@@ -1355,7 +1354,7 @@ def create_value_transform(echo_nostr, echo_noarr):
             f_val = getattr(val, f)
             if echo_noarr and '[' in t:
                 setattr(val_trans, f, '<array type: %s, length: %s>' %
-                                (t.rstrip('[]'), len(f_val)))
+                                      (t.rstrip('[]'), len(f_val)))
                 val_trans._slot_types[index] = 'string'
             elif echo_nostr and 'string' in t:
                 setattr(val_trans, f, '<string length: %s>' % len(f_val))

@dirk-thomas dirk-thomas closed this Aug 8, 2016
@wkentaro wkentaro deleted the rostopic-echo-show-stat branch August 9, 2016 01:07
@wkentaro
Copy link
Contributor Author

wkentaro commented Aug 9, 2016

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants