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
00009
00010
00011
00012
00013 const double max_speed_x = 0.1;
00014 const double max_speed_y = 0.05;
00015 const double max_rotation = 0.2;
00016 double vel_x, vel_y, vel_rot;
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){
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){
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
00049 ros::Publisher vel_pub = n.advertise<geometry_msgs::Twist>("cmd_vel", 10);
00050
00051 ros::Subscriber joy_sub = n.subscribe( "joy", 10, &joyCallback );
00052
00053 ros::Rate loop_rate(100);
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