biped_joystick_center.cpp
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 Dieser Knoten verarbeitet die joy_msg von joy/joy_node und erzeugt daraus eine geometry_msgs::Twist die x y und rotation um die Z achse and den bipedRobin_teleop/biped_teleop knoten weitergibt.
00010 Weiters werden mit den Tasten auf dem Joypad verschiedene Services im bipedRobin_driver/biped_serializer Knoten aufgerufen
00011 Und es kann die Freigabe zum gehen and den bipedRobin_navigation/navigation_master gesendet werden
00012 */
00013 ros::ServiceClient acknowledge_client; //zum Aufrufen des Acknowledge services
00014 ros::ServiceClient setMode_client; //zum Aufrufen des setMode services
00015 ros::ServiceClient stop_client; //zum Aufrufen des stop services
00016 ros::ServiceClient walk_client; //zum Aufrufen des stop services
00017 ros::Publisher speech_pub;
00018 
00019 void joyCallback( const sensor_msgs::Joy::ConstPtr& joy_msg )
00020 {
00021         biped_robin_msgs::SetModeService setMode; //Nachrichten für services
00022         std_srvs::Empty empty;
00023 
00024         if(joy_msg->buttons[0] == 1){   //Knopf 1 setServiceMode 0
00025                 setMode.request.desiredMode = 0;
00026                 setMode_client.call(setMode);
00027         }
00028 
00029         if(joy_msg->buttons[1] == 1){   //Knopf 2 setServiceMode 2
00030                 setMode.request.desiredMode = 2;
00031                 setMode_client.call(setMode);
00032         }
00033 
00034         if(joy_msg->buttons[2] == 1){   //Knopf 3 setServiceMode 3
00035                 setMode.request.desiredMode = 3;
00036                 setMode_client.call(setMode);
00037         }
00038 
00039         if(joy_msg->buttons[3] == 1){   //Knopf 4 walk_srv
00040                 walk_client.call(empty);
00041         }
00042 
00043         if(joy_msg->buttons[8] == 1){   //Knopf SE acknowledge service
00044                 acknowledge_client.call(empty);
00045         }
00046 
00047         if(joy_msg->buttons[9] == 1){   //Knopf ST stop service
00048                 stop_client.call(empty);
00049         }
00050         if(joy_msg->axes[4] == 1){ // Analog Joystick --> talk
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){ // Analog Joystick --> talk
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){ // Analog Joystick --> talk
00061                 std_msgs::String str;
00062                 str.data = "You are welcome!";
00063                 speech_pub.publish(str);
00064         }
00065         if(joy_msg->axes[5] == -1){ // Analog Joystick --> talk
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         //subscriber for joy/joy_node
00078         ros::Subscriber joy_sub = n.subscribe( "joy", 10, &joyCallback );
00079         //advertiser for speech output
00080         speech_pub = n.advertise<std_msgs::String>("speech",5);
00081         //service clients for bipedRobin_driver/biped_serializer
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         //service client fo bipedRobin_navigation/navigation_master,
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 


biped_robin_driver
Author(s): Johannes Mayr
autogenerated on Mon Jan 6 2014 11:07:54