osrf / rosbook

Example code to accompany the book Programming Robots with ROS
Apache License 2.0
484 stars 236 forks source link

key_publisher.py does not work #49

Open KansaiUser opened 3 years ago

KansaiUser commented 3 years ago

The code related with key_publisher does not work. It has two issues

  1. The keystrokes are not captured
  2. After Ctrl-C the keystroke capturing is not restored so it makes the terminal unusable.
codebot commented 3 years ago

Is there any terminal output? What operating system and version are you using?

amjadmajid commented 3 years ago

To fix this issue replace old_attr = termios.tcgetattr(sys.stdin) with old_attr = termios.tcgetattr(sys.stdin.fileno())

codebot commented 3 years ago

I just ran this on python2 and python3 and it seemed to work (?) what version of Python are you using, and what OS ?

amjadmajid commented 3 years ago

I using Python 3.8.10 on Ubuntu 20.04 (btw, thanks for your impressive work!).

HocheolShin commented 2 years ago

It's because rate.sleep() doesn't work properly. It hold system so that the while loop doesn't go around. If you terminate the program with Ctrl+C, the system doesn't receive the old terminal attribute. I don't know why rate.sleep() doesn't work, but I can go around it by using time.sleep(). If I want to use rate=rospy.Rate(10) # 10Hz, I use time.sleep(0.1) instead of rate.sleep(). It's not same but works.