Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <ros/ros.h>
00022 #include <geometry_msgs/Twist.h>
00023 #include <std_msgs/String.h>
00024 #include "boost/thread/mutex.hpp"
00025 #include "boost/thread/thread.hpp"
00026 #include "ros/console.h"
00027 #include <string>
00028
00029 std_msgs::String readCommand;
00030
00031 class RobotVoiceTeleop
00032 {
00033 public:
00034 RobotVoiceTeleop();
00035
00036 private:
00037 void commandCallBack(const std_msgs::String& command);
00038 void publish();
00039
00040 ros::NodeHandle nodeHandle;
00041
00042
00043 int linearVelocity, angularVelocity;
00044 ros::Publisher velocityPublisher;
00045 ros::Subscriber voiceCommandSubscriber;
00046 geometry_msgs::Twist cmd_vel;
00047
00048
00049 };
00051 RobotVoiceTeleop::RobotVoiceTeleop():
00052 nodeHandle("~"),
00053 linearVelocity(1),
00054 angularVelocity(0)
00055 {
00056 nodeHandle.param("linear_velocity", linearVelocity, linearVelocity);
00057 nodeHandle.param("angular_velocity", angularVelocity, angularVelocity);
00058
00059 velocityPublisher = nodeHandle.advertise<geometry_msgs::Twist>("/cmd_vel", 1);
00060 voiceCommandSubscriber = nodeHandle.subscribe("/recognizer/output", 1000, &RobotVoiceTeleop::commandCallBack, this);
00061
00062 printf("start control\n");
00063 ros::Rate rate(5);
00064 while (ros::ok()){
00065 velocityPublisher.publish(cmd_vel);
00066 rate.sleep();
00067 ros::spinOnce();
00068 }
00069
00070 }
00072 void RobotVoiceTeleop::commandCallBack(const std_msgs::String& command)
00073 {
00074 if(command.data.compare("stop") == 0)
00075 {
00076 cmd_vel.angular.z = 0;
00077 cmd_vel.linear.x = 0;
00078 }
00079 else if(command.data.compare("forward") == 0)
00080 {
00081 cmd_vel.linear.x = 0.3;
00082 cmd_vel.angular.z = 0;
00083 }
00084 else if(command.data.compare("backward") == 0)
00085 {
00086 cmd_vel.linear.x = -0.3;
00087 cmd_vel.angular.z = 0;
00088 }
00089 else if(command.data.compare("left") == 0)
00090 {
00091 cmd_vel.linear.x = 0.0;
00092 cmd_vel.angular.z = 0.5;
00093 }
00094 else if(command.data.compare("right") == 0)
00095 {
00096 cmd_vel.linear.x = 0.0;
00097 cmd_vel.angular.z = -0.5;
00098 }
00099 else {
00100 cmd_vel.angular.z = 0;
00101 cmd_vel.linear.x = 0;
00102 }
00103
00104 printf("cmd_vel.linear.x = %.2f, cmd_vel.angular.z = %.2f\n", cmd_vel.linear.x, cmd_vel.angular.z);
00105
00106 }
00107
00108
00109 int main(int argc, char** argv)
00110 {
00111 ros::init(argc, argv, "voice_teleop_node");
00112 RobotVoiceTeleop voice_teleop;
00113 ros::spin();
00114 }