Go to the documentation of this file.00001 #include "ros/ros.h"
00002 #include "sensor_msgs/Joy.h"
00003 #include "geometry_msgs/Twist.h"
00004 #include "biped_robin_msgs/SetModeService.h"
00005 #include "std_srvs/Empty.h"
00006 #include "std_msgs/String.h"
00007
00008
00009
00010
00011
00012
00013 ros::ServiceClient acknowledge_client;
00014 ros::ServiceClient setMode_client;
00015 ros::ServiceClient stop_client;
00016 ros::ServiceClient walk_client;
00017 ros::Publisher speech_pub;
00018
00019 void joyCallback( const sensor_msgs::Joy::ConstPtr& joy_msg )
00020 {
00021 biped_robin_msgs::SetModeService setMode;
00022 std_srvs::Empty empty;
00023
00024 if(joy_msg->buttons[0] == 1){
00025 setMode.request.desiredMode = 0;
00026 setMode_client.call(setMode);
00027 }
00028
00029 if(joy_msg->buttons[1] == 1){
00030 setMode.request.desiredMode = 2;
00031 setMode_client.call(setMode);
00032 }
00033
00034 if(joy_msg->buttons[2] == 1){
00035 setMode.request.desiredMode = 3;
00036 setMode_client.call(setMode);
00037 }
00038
00039 if(joy_msg->buttons[3] == 1){
00040 walk_client.call(empty);
00041 }
00042
00043 if(joy_msg->buttons[8] == 1){
00044 acknowledge_client.call(empty);
00045 }
00046
00047 if(joy_msg->buttons[9] == 1){
00048 stop_client.call(empty);
00049 }
00050 if(joy_msg->axes[4] == 1){
00051 std_msgs::String str;
00052 str.data = "Hello! I am a biped robot. I have two legs and can walk like a human. Do you want to see it?";
00053 speech_pub.publish(str);
00054 }
00055 if(joy_msg->axes[5] == 1){
00056 std_msgs::String str;
00057 str.data = "Did you like it?";
00058 speech_pub.publish(str);
00059 }
00060 if(joy_msg->axes[4] == -1){
00061 std_msgs::String str;
00062 str.data = "You are welcome!";
00063 speech_pub.publish(str);
00064 }
00065 if(joy_msg->axes[5] == -1){
00066 std_msgs::String str;
00067 str.data = "Thank you for visiting me. I hope you enjoyed my demonstrations and will visit me again.";
00068 speech_pub.publish(str);
00069 }
00070 }
00071
00072 int main(int argc, char** argv)
00073 {
00074 ros::init(argc, argv, "biped_joystick_center");
00075 ros::NodeHandle n;
00076
00077
00078 ros::Subscriber joy_sub = n.subscribe( "joy", 10, &joyCallback );
00079
00080 speech_pub = n.advertise<std_msgs::String>("speech",5);
00081
00082 setMode_client = n.serviceClient<biped_robin_msgs::SetModeService>("setMode_srv");
00083 acknowledge_client = n.serviceClient<std_srvs::Empty>("acknowledge_srv");
00084 stop_client = n.serviceClient<std_srvs::Empty>("stop_srv");
00085
00086 walk_client = n.serviceClient<std_srvs::Empty>("walk_srv");
00087
00088 ros::Rate loop_rate(100);
00089 while( ros::ok() )
00090 {
00091 ros::spinOnce();
00092
00093 loop_rate.sleep();
00094 }
00095 }
00096