keyop_core.hpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012, Yujin Robot.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of Yujin Robot nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00037 /*****************************************************************************
00038  ** Ifdefs
00039  *****************************************************************************/
00040 
00041 #ifndef KEYOP_CORE_NODE_HPP_
00042 #define KEYOP_CORE_NODE_HPP_
00043 
00044 /*****************************************************************************
00045  ** Includes
00046  *****************************************************************************/
00047 
00048 #include <ros/ros.h>
00049 #include <termios.h> // for keyboard input
00050 #include <ecl/threads.hpp>
00051 #include <geometry_msgs/Twist.h>  // for velocity commands
00052 #include <geometry_msgs/TwistStamped.h>  // for velocity commands
00053 #include <kobuki_msgs/KeyboardInput.h> // keycodes from remote teleops.
00054 
00055 /*****************************************************************************
00056  ** Namespaces
00057  *****************************************************************************/
00058 
00059 namespace keyop_core
00060 {
00061 
00062 /*****************************************************************************
00063  ** Interface
00064  *****************************************************************************/
00069 class KeyOpCore
00070 {
00071 public:
00072   /*********************
00073    ** C&D
00074    **********************/
00075   KeyOpCore();
00076   ~KeyOpCore();
00077   bool init();
00078 
00079   /*********************
00080    ** Runtime
00081    **********************/
00082   void spin();
00083 
00084 private:
00085   ros::Subscriber keyinput_subscriber;
00086   ros::Publisher velocity_publisher_;
00087   ros::Publisher motor_power_publisher_;
00088   bool last_zero_vel_sent;
00089   bool accept_incoming;
00090   bool power_status;
00091   bool wait_for_connection_;
00092   geometry_msgs::TwistPtr cmd;
00093   geometry_msgs::TwistStampedPtr cmd_stamped;
00094   double linear_vel_step, linear_vel_max;
00095   double angular_vel_step, angular_vel_max;
00096   std::string name;
00097 
00098   /*********************
00099    ** Commands
00100    **********************/
00101   void enable();
00102   void disable();
00103   void incrementLinearVelocity();
00104   void decrementLinearVelocity();
00105   void incrementAngularVelocity();
00106   void decrementAngularVelocity();
00107   void resetVelocity();
00108 
00109   /*********************
00110    ** Keylogging
00111    **********************/
00112 
00113   void keyboardInputLoop();
00114   void processKeyboardInput(char c);
00115   void remoteKeyInputReceived(const kobuki_msgs::KeyboardInput& key);
00116   void restoreTerminal();
00117   bool quit_requested;
00118   int key_file_descriptor;
00119   struct termios original_terminal_state;
00120   ecl::Thread thread;
00121 };
00122 
00123 } // namespace keyop_core
00124 
00125 #endif /* KEYOP_CORE_NODE_HPP_ */


kobuki_keyop
Author(s): Daniel Stonier
autogenerated on Mon Oct 6 2014 01:32:18