joystick_teleop.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 "bipedRobin_msgs/SetModeService.h"
00005 #include "std_srvs/Empty.h"
00006 
00007 /*
00008 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.
00009 Weiters werden mit den Tasten auf dem Joypad verschiedene Services im bipedRobin_driver/biped_serializer Knoten aufgerufen
00010 Und es kann die Freigabe zum gehen and den bipedRobin_navigation/navigation_master gesendet werden
00011 */
00012 
00013 const double max_speed_x = 0.1; // m/s
00014 const double max_speed_y = 0.05; // m/s
00015 const double max_rotation = 0.2; // rad/s
00016 double vel_x, vel_y, vel_rot; // Geschwindigkeiten
00017 
00018 void joyCallback( const sensor_msgs::Joy::ConstPtr& joy_msg )
00019 {
00020         if( joy_msg->axes.size() < 3 )
00021         {
00022                 ROS_ERROR( "Too few joystick axes: %d (expected: 3+)", joy_msg->axes.size() );
00023                 return;
00024         }
00025 
00026         ROS_DEBUG("Received [axis0=%f axis1=%f axis2=%f]", joy_msg->axes[0], joy_msg->axes[1], joy_msg->axes[2] );
00027         
00028         if(joy_msg->buttons[4] == 1){   //L1 als Totmannschalter
00029                 vel_x = joy_msg->axes[1] * max_speed_x;
00030                 vel_y = joy_msg->axes[0] * max_speed_y;
00031         } else {
00032                 vel_x = 0;
00033                 vel_y = 0;
00034         }
00035 
00036         if(joy_msg->buttons[5] == 1){ //R1 als Totmannschalter
00037                 vel_rot = joy_msg->axes[2] * max_rotation;
00038         } else {
00039                 vel_rot = 0;
00040         }
00041 }
00042 
00043 int main(int argc, char** argv)
00044 {
00045         ros::init(argc, argv, "biped_teleop_joy_node");
00046         ros::NodeHandle n;
00047 
00048         //publisher for cmd_vel and bipedRobin_teleop/biped_teleop
00049         ros::Publisher  vel_pub = n.advertise<geometry_msgs::Twist>("cmd_vel", 10);
00050         //subscriber for joy/joy_node
00051         ros::Subscriber joy_sub = n.subscribe( "joy", 10, &joyCallback );
00052 
00053         ros::Rate loop_rate(100); //publishen der Twist message mit 100 Hz
00054         while( ros::ok() ) 
00055         {
00056                 geometry_msgs::Twist twist_msg;
00057                 twist_msg.linear.x = vel_x;
00058                 twist_msg.linear.y = vel_y;
00059                 twist_msg.angular.z = vel_rot;
00060 
00061                 if (1 || vel_x != 0 || vel_y != 0 || vel_rot != 0) {
00062                         vel_pub.publish(twist_msg);
00063                 }
00064 
00065                 loop_rate.sleep();
00066                 ros::spinOnce();
00067         }
00068 }
00069 


bipedRobin_teleop
Author(s): Johannes Mayr
autogenerated on Fri Nov 15 2013 11:11:03