Go to the documentation of this file.00001
00002
00003 import roslib; roslib.load_manifest('move_base_stage_tutorial')
00004
00005 import rospy
00006 from geometry_msgs.msg import Twist
00007
00008 import sys, select, termios, tty
00009 def getKey():
00010 tty.setraw(sys.stdin.fileno())
00011 select.select([sys.stdin], [], [], 0)
00012 key = sys.stdin.read(1)
00013 termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)
00014 return key
00015
00016 move = {
00017 'w' : lambda : (1,0,0),
00018 'a' : lambda : (0,1,0),
00019 's' : lambda : (-1,0,0),
00020 'd' : lambda : (0,-1,0),
00021 'q' : lambda : (0,0,1),
00022 'e' : lambda : (0,0,-1),
00023 }
00024 if __name__ == '__main__':
00025 print """
00026 Reading from keyboard
00027 ---------------------------
00028 Use 'WASD' to translate
00029 Use 'E' to yaw
00030 Press 'Enter' to run
00031 Press 'Q' to quit
00032 """
00033
00034 settings = termios.tcgetattr(sys.stdin)
00035
00036 try:
00037 pub = rospy.Publisher('cmd_vel', Twist);
00038 rospy.init_node('send_velocity', anonymous=True)
00039 r = rospy.Rate(10)
00040 while not rospy.is_shutdown() :
00041 key = getKey()
00042 print key
00043 if key in ['q', 27]:
00044 break
00045 elif key in move.keys() :
00046 print key,move[key]()
00047 cmd = Twist()
00048 cmd.linear.x = move[key]()[0]
00049 cmd.linear.y = move[key]()[1]
00050 cmd.angular.z = move[key]()[2]
00051 print "publish ",cmd
00052 pub.publish(cmd)
00053 r.sleep()
00054 except rospy.ROSInterruptException: pass
00055
00056