Go to the documentation of this file.00001
00002
00003 import rospy
00004 from geometry_msgs.msg import Twist
00005 from std_msgs.msg import String
00006
00007 class RobotVoiceTeleop:
00008
00009 def __init__(self):
00010
00011 rospy.init_node('voice_teleop')
00012
00013
00014 self.cmd_vel_pub = rospy.Publisher('/cmd_vel', Twist, queue_size=5)
00015
00016
00017 rospy.Subscriber('/recognizer/output', String, self.voice_command_callback)
00018
00019
00020 rate = rospy.Rate(5)
00021
00022
00023 self.cmd_vel = Twist()
00024
00025 self.cmd_vel.linear.x=0;
00026 self.cmd_vel.angular.z=0;
00027
00028
00029
00030
00031
00032 self.commands = ['stop',
00033 'forward',
00034 'backward',
00035 'turn left',
00036 'turn right',
00037 ]
00038 rospy.loginfo("Ready to receive voice commands")
00039
00040 while not rospy.is_shutdown():
00041 self.cmd_vel_pub.publish(self.cmd_vel)
00042 rate.sleep()
00043
00044
00045 def voice_command_callback(self, msg):
00046
00047 command = msg.data
00048 if (command in self.commands):
00049 if command == 'forward':
00050 self.cmd_vel.linear.x = 0.2
00051 self.cmd_vel.angular.z = 0.0
00052 elif command == 'backward':
00053 self.cmd_vel.linear.x = -0.2
00054 self.cmd_vel.angular.z = 0.0
00055 elif command == 'turn left':
00056 self.cmd_vel.linear.x = 0.0
00057 self.cmd_vel.angular.z = 0.5
00058 elif command == 'turn right':
00059 self.cmd_vel.linear.x = 0.0
00060 self.cmd_vel.angular.z = -0.5
00061 elif command == 'stop':
00062 self.cmd_vel.linear.x = 0.0
00063 self.cmd_vel.angular.z = 0.0
00064
00065 else:
00066
00067 self.cmd_vel.linear.x = 0.0
00068 self.cmd_vel.angular.z = 0.0
00069 print ("linear speed : " + str(self.cmd_vel.linear.x))
00070 print ("angular speed: " + str(self.cmd_vel.angular.z))
00071
00072
00073
00074 if __name__=="__main__":
00075 try:
00076 RobotVoiceTeleop()
00077 rospy.spin()
00078 except rospy.ROSInterruptException:
00079 rospy.loginfo("Voice navigation terminated.")
00080