0
$\begingroup$

Rosanswers logo

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.


Originally posted by abrzozowski on ROS Answers with karma: 290 on 2016-10-24

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by mgruhler with karma: 12390 on 2016-10-24

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by abrzozowski on 2016-10-24:
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.

Comment by 130s on 2017-02-17:
PR was opened and merged.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.