35 from geometry_msgs.msg
import Twist
36 from nav_msgs.msg
import Odometry
42 rospy.signal_shutdown(
"exit")
47 CURRENT_ODOM = Odometry()
50 DOWN_KEY = [27, 91, 66]
51 LEFT_KEY = [27, 91, 68]
52 RIGHT_KEY = [27, 91, 67]
61 cmd.linear.x = CURRENT_ODOM.twist.twist.linear.x
62 cmd.angular.z = CURRENT_ODOM.twist.twist.angular.z
77 global CURRENT_KEY, KEY_CACHE
85 elif len(KEY_CACHE) != 0:
86 KEY_CACHE.append(ord(c))
87 if KEY_CACHE == LEFT_KEY:
89 if KEY_CACHE == RIGHT_KEY:
91 if KEY_CACHE == UP_KEY:
93 if KEY_CACHE == DOWN_KEY:
95 if len(KEY_CACHE) == 3:
104 if __name__ ==
"__main__":
106 rospy.init_node(
'xiaoqiang_controller', anonymous=
True)
107 rospy.loginfo(
"Welcome to use xiaoqiang controller.")
108 rospy.loginfo(
"Use arrow keys to move robot around.")
109 rospy.loginfo(
"Use space to stop robot.")
110 rospy.loginfo(
"Use Ctrl + C to exit.")
113 signal.signal(signal.SIGINT, signal_handler)
115 fd = sys.stdin.fileno()
117 old_term = termios.tcgetattr(fd)
118 new_attr = termios.tcgetattr(fd)
119 new_attr[3] = new_attr[3] & ~termios.ICANON & ~termios.ECHO
120 termios.tcsetattr(fd, termios.TCSANOW, new_attr)
122 old_flags = fcntl.fcntl(fd, fcntl.F_GETFL)
123 fcntl.fcntl(fd, fcntl.F_SETFL, old_flags | os.O_NONBLOCK)
125 cmd_pub = rospy.Publisher(
'/cmd_vel', Twist, queue_size=0)
126 rospy.Subscriber(
"/xiaoqiang_driver/odom", Odometry, update_speed)
128 thread.start_new_thread(get_current_key, ())
131 while not rospy.is_shutdown():
def signal_handler(signal, frame)