uos_diffdrive_teleop_wiimote.cpp
Go to the documentation of this file.
00001 /*This program will run the robot in three different speeds
00002  The buttons array shows which buttons are currently depressed on the Wiimote device.
00003  The position mapping is as follows:
00004  Position   Button Name
00005  0         1
00006  1         2
00007  2         A
00008  3         B (toggle button on back of device)
00009  4         Plus
00010  5         Minus
00011  6         Rocker Left
00012  7         Rocker Right
00013  8         Rocker Up
00014  9         Rocker Down
00015  10        HOME
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; // assigning three cases based on three buttons on the wii remote
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   //choosing speed and assigning it to max_vel
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   // assigning x and z value in the Twist message
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 


uos_diffdrive_teleop
Author(s): Jochen Sprickerhof
autogenerated on Mon Oct 6 2014 12:20:47