00001 /********************************************************************* 00002 * 00003 * Software License Agreement (BSD License) 00004 * 00005 * Copyright (c) 2012, Kevin J. Walchko. 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 00010 * are 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 00016 * disclaimer in the documentation and/or other materials provided 00017 * with the distribution. 00018 * * Neither the name of Kevin nor the names of its 00019 * contributors may be used to endorse or promote products derived 00020 * from 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 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 * POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 * Author: Kevin J. Walchko on 9/9/2012 00036 ********************************************************************* 00037 * 00038 * Change Log: 00039 * 9 Sep 2012 Created 00040 * 00041 ********************************************************************** 00042 * 00043 * 00044 * 00045 */ 00046 00047 //--- C++ --------------------- 00048 #include <math.h> 00049 #include <stdlib.h> 00050 #include <stdio.h> 00051 #include <string.h> 00052 00053 //--- Boost -------------------- 00054 #include <boost/program_options.hpp> // command line options 00055 namespace po = boost::program_options; 00056 00057 //--- ROS --------------------- 00058 #include <ros/ros.h> 00059 00060 //--- Joystick ---------------- 00061 #include "JoyStick.h" 00062 00063 00064 int main(int argc, char *argv[]){ 00065 00066 // init ROS 00067 ros::init(argc, argv, "joystick"); 00068 00069 int joy_num = 0; 00070 float hz = 30.0; 00071 00072 //--- Handle commandline options --------------------------------------------- 00073 po::options_description desc("Allowed options"); 00074 desc.add_options() 00075 ("help", "produce help message") 00076 ("num", po::value<int>(),"which joystick to use, default is 0") 00077 ("hz", po::value<float>(), "polling frequency in Hz, default is 30 Hz") 00078 ; 00079 po::variables_map vm; 00080 po::store(po::parse_command_line(argc, argv, desc), vm); 00081 po::notify(vm); 00082 00083 if (vm.count("help")) { 00084 //std::cout << "rosrun ahrs ahrs [option] \n"; 00085 //std::cout << " default topic in [imu] out [imu_out] \n"; 00086 std::cout << desc << "\n"; 00087 return 0; 00088 } 00089 00090 if (vm.count("num")){ 00091 joy_num = vm["num"].as<int>(); 00092 } 00093 00094 if (vm.count("hz")){ 00095 hz = vm["hz"].as<float>(); 00096 } 00097 00098 // init the GLFW library 00099 if( !glfwInit() ){ 00100 ROS_ERROR("Failed to initialize GLFW" ); 00101 exit(1); 00102 } 00103 //------------------------------------------------------------------------------- 00104 00105 TwistJoyStick js(joy_num); 00106 js.setUpPublisher(); 00107 js.spin(hz); 00108 00109 // Terminate GLFW 00110 glfwTerminate(); 00111 00112 // Exit program 00113 exit(0); 00114 } 00115