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] Fix rostopic echo for non rosmsg field #909

Merged
merged 4 commits into from
Sep 30, 2016

Conversation

wkentaro
Copy link
Contributor

Close #908

@dirk-thomas
Copy link
Member

If you run roslaunch rospy_tutorials talker_listener.launch and rostopic echo /chatter --nostr it prints:

data: <string length: 25>

Therefore I would expect rostopic echo /chatter --nostr -n 1 to print:

<string length: 25>

but it actually prints:

None

@@ -1389,6 +1389,12 @@ def eval_fn(m):

def create_value_transform(echo_nostr, echo_noarr):
def value_transform(val):
if not isinstance(val, genpy.Message):
if echo_nostr and isinstance(val, str):
return None
Copy link
Member

Choose a reason for hiding this comment

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

What about this instead:

return '<string length: %s>' % len(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.

Nice.

if echo_nostr and isinstance(val, str):
return None
elif echo_noarr and isinstance(val, list):
return None
Copy link
Member

@dirk-thomas dirk-thomas Sep 29, 2016

Choose a reason for hiding this comment

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

Here I don't see how we could print the type information (<array type: ??? ...>):

return '<array length: %s>' % len(val)

@wkentaro
Copy link
Contributor Author

With 47adb6d,

% rostopic echo /rosout/msg --nostr
<string length: 24>
---

% rostopic echo /rosout/topics --noarr
<array type: string, length: 2>
---

@wkentaro
Copy link
Contributor Author

wkentaro commented Sep 29, 2016

With 9dd94cf,

Before

% rostopic echo /rosout --nostr -n1
header:
  seq: 13891
  stamp:
    secs: 1475187530
    nsecs: 501231908
  frame_id: <string length: 0>
level: 2
name: <string length: 9>
msg: <string length: 41>
file: <string length: 11>
function: <string length: 8>
line: 43
topics: <string length: 2>

After

% rostopic echo /rosout --nostr -n1
header:
  seq: 14060
  stamp:
    secs: 1475187547
    nsecs: 301131010
  frame_id: <string length: 0>
level: 2
name: <string length: 9>
msg: <string length: 41>
file: <string length: 11>
function: <string length: 8>
line: 43
topics: <array type: string, length: 2>
---

@dirk-thomas
Copy link
Member

The current patch duplicates a lot of code / logic. I would recommend to create a function like this:

def _value_transform(type_information, val, echo_nostr, echo_noarr):
    if echo_noarr and '[' in type_information:
        return '<array type: %s, length: %s>' % \
            (type_information.rstrip('[]'), len(val))
    elif echo_nostr and type_information == 'string':
        return '<string length: %s>' % len(val)
    elif echo_nostr and type_information == 'string[]':
        return '<array type: string, length: %s>' % len(val)
    return None

and call it from the two locations accordingly.

@dirk-thomas
Copy link
Member

This looks good to me. Thank you for providing this patch so fast.

@dirk-thomas dirk-thomas merged commit 8babe82 into ros:kinetic-devel Sep 30, 2016
@wkentaro wkentaro deleted the echo-not-rosmsg branch September 30, 2016 19:03
@mikepurvis
Copy link
Member

Thanks for the quick turnaround, all.

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

Successfully merging this pull request may close these issues.

3 participants