Ask Your Question
1

Command line: rostopic pub - why is required specify a topic type?

asked 2016-10-24 04:03:58 -0500

abrzozowski gravatar image

updated 2020-10-19 15:51:34 -0500

I'm unsure why i must specify a rostopic type, while invoke a rostopic pub command.

rostopic pub /topic type [args...]

I think, that a message type can be deduced by internal call a rostopic info on a rostopic name.

So, after all you can improve your rosbash file to deduct the topic type

# rosbash
778 pub)
779         if [[ $COMP_CWORD == 2 ]]; then
780                 opts=`rostopic list 2> /dev/null`
781                 COMPREPLY=($(compgen -W "$opts" -- ${arg}))
782         elif [[ $COMP_CWORD == 3 ]]; then
783                 opts=`_msg_opts ${COMP_WORDS[$COMP_CWORD]}`
784                 COMPREPLY=($(compgen -W "$opts" -- ${arg}))

changing the line 783 to:

opts=`rostopic info ${COMP_WORDS[$COMP_CWORD-1]} | head -n 1 | awk '{print $2}'`

or after mig advice:

opts=`rostopic info ${COMP_WORDS[$COMP_CWORD-1]} 2> /dev/null | head -n 1 | awk '{print $2}'`
if [ -z $opts ]; then
    opts=`_msg_opts ${COMP_WORDS[$COMP_CWORD]}`
fi

Please correct my misunderstanding about a rostopic pub.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2016-10-24 04:20:31 -0500

mgruhler gravatar image

This will only work if the topic is already registered. Even though the idea is, in general, valid, if you want to do a rostopic pub on a topic that has no publishers or subscribers so far, this deduction will fail. I guess this is why the choice has been to include this.

You could obvisously try to include this as well and set up a PR.

edit flag offensive delete link more

Comments

Ok, to protect against no registered topic you can easly improve snippet to:

opts=`rostopic info ${COMP_WORDS[$COMP_CWORD-1]} 2> /dev/null | head -n 1 | awk '{print $2}'`
if [ -z $opts ]; then
    opts=`_msg_opts ${COMP_WORDS[$COMP_CWORD]}`
fi

Thanks for your suggestions.

abrzozowski gravatar image abrzozowski  ( 2016-10-24 08:09:51 -0500 )edit

PR was opened and merged.

130s gravatar image 130s  ( 2017-02-17 12:40:03 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

Asked: 2016-10-24 04:03:58 -0500

Seen: 748 times

Last updated: Oct 19 '20