ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How can I get real-time input from user?

asked 2013-05-27 05:18:40 -0500

Behzad_a gravatar image

updated 2014-01-28 17:16:39 -0500

ngrennan gravatar image

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.

edit retag flag offensive close merge delete

Comments

Are you trying to run this python file with rosrun or with roslaunch?

askkvn gravatar image askkvn  ( 2019-06-14 06:59:00 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
4

answered 2013-05-28 21:47:12 -0500

goetz.marc gravatar image

updated 2013-05-28 21:49:13 -0500

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.

edit flag offensive delete link more

Comments

Are you trying to run this python file with rosrun or with roslaunch?

askkvn gravatar image askkvn  ( 2019-06-14 06:59:45 -0500 )edit
2

answered 2013-05-28 12:18:37 -0500

HenryW gravatar image

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

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-05-27 05:18:40 -0500

Seen: 11,104 times

Last updated: May 28 '13