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

Revision history [back]

click to hide/show revision 1
initial version

Your code isn't well-formatted, so it's pretty difficult to read and understand, but my best guess is that you aren't doing the keyboard I/O properly. I suspect there's nothing wrong with the ROS parts of your code.

You can test if you have the I/O wrong by trying to use the q command to quit. If you push q by itself, I suspect nothing will happen. If you push q 2-3 times and then push enter, I suspect your program will exit.

The trouble here is that, by default, terminal input is line-buffered and "cooked", meaning that your program doesn't get any input until the user has entered an entire line and pushed enter, and that the terminal will strip or reinterpret nonprinting characters such as arrow keys and the control key.

There are lots of good resources for understanding non-blocking terminal input. You can either grab your favorite systems programming book, or consult Google and StackOverflow. This StackOverflow question seems to do a good job of describing the basics.

And don't forget to have your program put your terminal back the way was on exit. The terminal device is shared between all process that run in that shell, and programs like ssh will fail in strange and unusual ways if you leave the terminal in non-blocking mode. (The stty sane will also put it back to normal).