Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <ros/ros.h>
00018 #include <geometry_msgs/Twist.h>
00019 #include <sensor_msgs/Joy.h>
00020
00021 double max_vel_x, max_rotational_vel;
00022 ros::Publisher vel_pub;
00023
00024 void ps3joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
00025 {
00026 geometry_msgs::Twist vel;
00027
00028 int c = 0;
00029 if (joy->buttons[0])
00030 c = 1;
00031 else if (joy->buttons[1])
00032 c = 2;
00033 else if (joy->buttons[3])
00034 c = 3;
00035
00036
00037 switch (c)
00038 {
00039 case 1:
00040 max_vel_x = 0.1;
00041 break;
00042 case 2:
00043 max_vel_x = 0.5;
00044 break;
00045 case 3:
00046 max_vel_x = 1.5;
00047 break;
00048 }
00049
00050
00051 if (joy->buttons[8])
00052 {
00053 vel.linear.x = max_vel_x;
00054 }
00055 else if (joy->buttons[9])
00056 {
00057 vel.linear.x = -max_vel_x;
00058 }
00059 else if (joy->buttons[6])
00060 {
00061 vel.angular.z = max_rotational_vel;
00062 }
00063 else if (joy->buttons[7])
00064 {
00065 vel.angular.z = -max_rotational_vel;
00066 }
00067 else
00068
00069 {
00070 vel.linear.x = 0;
00071 vel.angular.z = 0;
00072 }
00073
00074 vel_pub.publish(vel);
00075 }
00076
00077 int main(int argc, char** argv)
00078 {
00079 ros::init(argc, argv, "uos_diffdrive_teleop_wiimote");
00080
00081 ros::NodeHandle nh;
00082 ros::NodeHandle nh_ns("~");
00083
00084 nh_ns.param("max_vel_x", max_vel_x, 1.5);
00085 nh_ns.param("max_rotational_vel", max_rotational_vel, 1.5);
00086
00087 vel_pub = nh.advertise<geometry_msgs::Twist>("cmd_vel", 1);
00088 ros::Subscriber ps3joy_sub = nh.subscribe("joy", 10, ps3joyCallback);
00089
00090 ros::spin();
00091 }
00092