0
$\begingroup$

Rosanswers logo

Hi everyone!

I'm trying to print a statement on the command line and then get inputs (strings to be more specific) from the user while my package is running. I'm writing my node in Python. Is there anyway to do this? I now this seems trivial, but I'm new to ROS and couldn't find anything regarding this problem on the web.

Thanks.

P.s. I tried print '....' but it doesn't print anything on the command line. I tried n=raw_input() but my node crashes.


Originally posted by Behzad_a on ROS Answers with karma: 13 on 2013-05-27

Post score: 1


Original comments

Comment by askkvn on 2019-06-14:
Are you trying to run this python file with rosrun or with roslaunch?

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

As HenryW already said, you can use the normal python method, for example

#!/usr/bin/env python

from rospy import init_node, is_shutdown

if __name__ == '__main__':

  init_node('input_test')

  while not is_shutdown():

      print "gimme something, please?"
      something = raw_input()
      print "thanks for giving me " + something

compiling this node and then running it leads to

gimme something, please?
beer
thanks for giving me beer
gimme something, please?
box
thanks for giving me box
gimme something, please?
plant
thanks for giving me plant
gimme something, please?

If this doesn't work for you, update your question with your code and error messages.


Originally posted by goetz.marc with karma: 203 on 2013-05-28

This answer was ACCEPTED on the original site

Post score: 4


Original comments

Comment by askkvn on 2019-06-14:
Are you trying to run this python file with rosrun or with roslaunch?

$\endgroup$
0
$\begingroup$

Rosanswers logo

As far as I am aware, you can use standard Python methods for getting input from the keyboard when making your program.


Originally posted by HenryW with karma: 140 on 2013-05-28

This answer was NOT ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

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