00001 /******************************************************************************* 00002 * 00003 * seabee3_teleop 00004 * 00005 * Copyright (c) 2010, Edward T. Kaszubski (ekaszubski@gmail.com) 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are 00010 * met: 00011 * 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * * Redistributions in binary form must reproduce the above 00015 * copyright notice, this list of conditions and the following disclaimer 00016 * in the documentation and/or other materials provided with the 00017 * distribution. 00018 * * Neither the name of the USC Underwater Robotics Team nor the names of its 00019 * contributors may be used to endorse or promote products derived from 00020 * this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00025 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00026 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00027 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00028 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00029 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00030 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00031 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 *******************************************************************************/ 00035 00036 #include <ros/ros.h> 00037 #include <geometry_msgs/Twist.h> 00038 #include <joy/Joy.h> 00039 00040 ros::Publisher * cmd_vel_pub; 00041 int speed, heading; 00042 double speed_s, heading_s; 00043 00044 bool buttonActionBusy = false; 00045 int buttonActionId = -1; 00046 00047 double applyDeadZone (double value) 00048 { 00049 return fabs(value) < 0.15f ? 0.0f : value; 00050 } 00051 00052 void joyCallback(const joy::Joy::ConstPtr& joy) 00053 { 00054 geometry_msgs::Twist cmd_vel; 00055 00056 double joy_speed = applyDeadZone( (double)(joy->axes[speed]) ); 00057 double joy_heading = applyDeadZone( (double)(joy->axes[heading]) ); 00058 00059 ROS_INFO("%f, %f", joy_speed, joy_heading); 00060 00061 cmd_vel.linear.x = speed_s * joy_speed; //speed 00062 cmd_vel.angular.z = heading_s * joy_heading; //heading 00063 00064 cmd_vel_pub->publish(cmd_vel); 00065 } 00066 00067 int main(int argc, char** argv) 00068 { 00069 ros::init(argc, argv, "beobot2_teleop"); 00070 ros::NodeHandle n; 00071 ros::NodeHandle n_priv("~"); 00072 00073 n.param("speed", speed, 1); 00074 n.param("heading", heading, 3); 00075 00076 n.param("speed_scale", speed_s, 1.0); 00077 n.param("heading_scale", heading_s, 1.0); 00078 00079 ros::Subscriber joy_sub = n_priv.subscribe("/joy", 1, joyCallback); 00080 00081 cmd_vel_pub = new ros::Publisher; 00082 *cmd_vel_pub = n_priv.advertise<geometry_msgs::Twist>("/beobot2/cmd_vel", 1); 00083 00084 ros::spin(); 00085 return 0; 00086 } 00087 00088